摘要: uint32_t reverseBits(uint32_t n) { int arr[32] = {0}; int i=0; while(n) { arr[i++] = n % 2; n /= 2; } for(i=0; i<32; i++) { n += (arr[i])? pow(2,32-1- 阅读全文
posted @ 2020-09-07 23:58 温暖了寂寞 阅读(119) 评论(0) 推荐(0) 编辑
摘要: int reverseBits(int num){ int max = 0,cnt = 0,cntPre = 0; while(num) { if(1 & num) cnt++; else { if(cntPre + cnt + 1 > max) max = cntPre + cnt + 1; cn 阅读全文
posted @ 2020-09-07 19:57 温暖了寂寞 阅读(165) 评论(0) 推荐(0) 编辑
摘要: void reverseString(char* s, int sSize){ int start =0,end = sSize-1,temp; while(start < end) temp = s[start],s[start++] = s[end],s[end--] = temp; } 阅读全文
posted @ 2020-09-07 18:24 温暖了寂寞 阅读(117) 评论(0) 推荐(0) 编辑
摘要: char * reverseStr(char * s, int k){ int len = strlen(s); for (int i = 0; i < len; i += 2 * k) { int left = i; int right = (i + k - 1 < len) ? i + k - 阅读全文
posted @ 2020-09-07 16:10 温暖了寂寞 阅读(98) 评论(0) 推荐(0) 编辑
摘要: char * reverseVowels(char * s){ char vowels[6] = {'a', 'e', 'i', 'o', 'u'}; int i = 0, j = strlen(s) - 1; char t; while (i < j){ if (strchr(vowels, to 阅读全文
posted @ 2020-09-07 14:41 温暖了寂寞 阅读(165) 评论(0) 推荐(0) 编辑
摘要: /*方法一:使用额外空间思路与算法开辟一个新字符串。然后从头到尾遍历原字符串,直到找到空格为止,此时找到了一个单词,并能得到单词的起止位置。随后,根据单词的起止位置,可以将该单词逆序放到新字符串当中。如此循环多次,直到遍历完原字符串,就能得到翻转后的结果。*/char * reverseWords( 阅读全文
posted @ 2020-09-07 14:16 温暖了寂寞 阅读(135) 评论(0) 推荐(0) 编辑
摘要: . bool judgeCircle(char * moves){ int n = strlen(moves),int count1=0,count2=0; for (int i=0; i<n; i++) { if (moves[i] == 'U') count1++; else if (moves 阅读全文
posted @ 2020-09-07 13:32 温暖了寂寞 阅读(151) 评论(0) 推荐(0) 编辑
摘要: int romanToInt(char * s){ int* hash = (int*)calloc(26,sizeof(int)); hash['I'-65] = 1; hash['V'-65] = 5; hash['X'-65] = 10; hash['L'-65] = 50; hash['C' 阅读全文
posted @ 2020-09-07 12:04 温暖了寂寞 阅读(99) 评论(0) 推荐(0) 编辑
摘要: bool rotateString(char * A, char * B){ if (strlen(A) != strlen(B)) return false; char* s = (char*)calloc(strlen(A)*2+1,sizeof(char)); strcat(strcat(s, 阅读全文
posted @ 2020-09-07 11:09 温暖了寂寞 阅读(107) 评论(0) 推荐(0) 编辑
摘要: bool judge(int x) { int num=0; while(x) { if (x % 10 == 3 || x % 10 == 4 || x % 10 == 7) return false; else if (x % 10 == 2 || x % 10 == 5 || x % 10 = 阅读全文
posted @ 2020-09-07 10:42 温暖了寂寞 阅读(143) 评论(0) 推荐(0) 编辑
摘要: int* runningSum(int* nums, int numsSize, int* returnSize){ for (int i=1; i<numsSize; i++) nums[i] += nums[i-1]; *returnSize = numsSize; return nums; } 阅读全文
posted @ 2020-09-07 10:21 温暖了寂寞 阅读(132) 评论(0) 推荐(0) 编辑
摘要: bool isSameTree(struct TreeNode* p, struct TreeNode* q){ if (!p && !q) return true; if(!p || !q || p->val != q->val) return false; return isSameTree(p 阅读全文
posted @ 2020-09-07 10:08 温暖了寂寞 阅读(96) 评论(0) 推荐(0) 编辑
摘要: int searchInsert(int* nums, int numsSize, int target){ for (int i=0; i<numsSize; i++) if (nums[i] >= target) return i; return numsSize; } 阅读全文
posted @ 2020-09-07 09:53 温暖了寂寞 阅读(113) 评论(0) 推荐(0) 编辑
摘要: struct TreeNode* searchBST(struct TreeNode* root, int val){ if (!root)?NULL: return (root->val==val)?root:(root->val<val)?searchBST(root->right,val):s 阅读全文
posted @ 2020-09-07 09:01 温暖了寂寞 阅读(98) 评论(0) 推荐(0) 编辑