leetcode
OliverkingLi
耶耶
展开
-
实现字符串的循环移动
实现字符串的循环移动: 循环移动某一给出的字符串,然后把前面k个字符拿到后面去,例如:abcdefg。我把前面3个字符拿到后面去变成:defgabc。实现这一算法的思路借助于线性代数的转置,(AB)^T = B^TA^T。因此把abcdefg拆成abc和defg两个字串,先把abc转置cba,然后吧defg转置gfed,拼接起来cbagfed,在转置得defgabc,即为所求,代原创 2018-01-23 21:00:29 · 580 阅读 · 0 评论 -
统计所给的unsigned型的数的二进制下1的个数
借助异或和分治的思想: #include int HaiMingWeight(unsigned int n){ n = (n & 0x55555555) + ((n & 0xaaaaaaaa) >> 1); n = (n & 0x33333333) + ((n & 0xcccccccc) >> 1); n = (n & 0x0f0f0f0f) + ((n & 0xf0f0f0f0) >>原创 2018-01-23 21:02:52 · 321 阅读 · 0 评论 -
求得给定字符串的全排列
给定字符串S[o...n-1],求出所有的S的全排列: ABC---ABC ACB BCA BAC CAB CBA 一:递归求法 #include #include using namespace std; void print_str(const int*a, int size){ for(int i=0; i < size; i++){ std::cout<<a[i原创 2018-01-23 21:58:15 · 875 阅读 · 0 评论 -
C++实现最长公共子序列LCS问题
LCLCS问题求解: #include #include #include #include #include using namespace std; void LCS(const char *str1, const char *str2, string &str){ int size_1 = (int)strlen(str1); int size_2 = (i原创 2018-01-24 10:16:07 · 565 阅读 · 0 评论 -
leetcode--str
import collections class Solution: def str2Str(self, source, target): if source is None or target is None: return False for i in range(len(source)-len(target) + 1): for j in range(len(targ原创 2018-01-18 11:33:06 · 263 阅读 · 0 评论