- 博客(12)
- 资源 (1)
- 收藏
- 关注
原创 LeetCode Best Time to Buy and Sell Stock II C 4ms
int maxProfit(int* prices, int pricesSize) { int max=0,i=0,muturs=0,buy=0,sell=0; for(i;i<pricesSize-1;i++){ if(prices[i]<=prices[i+1]) { if(muturs&&sell)
2016-01-31 14:31:05 228
原创 LeetCode Excel Sheet Column Number
int titleToNumber(char* s) { int length=strlen(s),num=0,i=0; while(i<length) { num=num+(s[i]-64)*pow(26,length-i-1);//方法一 //num=s[i]-64+num*26;//方法二 i++; }
2016-01-31 00:06:38 197
原创 LeetCode Valid Anagram Hashtable
bool isAnagram(char* s, char* t) { int ls=strlen(s),lt=strlen(t),i=0,su[26],lu[26]; memset(su, 0, sizeof(int)*26); memset(lu, 0, sizeof(int)*26); if(ls!=lt) return false; e
2016-01-30 23:17:53 245
原创 Excel Sheet Column Title
char* convertToTitle(int n) { char *asc1; int i=0,j,high,temp=n; while((temp-1)/26!=0)//第二种思考方式的时候这个循环将无用 { i++; temp=(temp-1)/26; } asc1 = (char *)mal
2016-01-30 22:22:47 264
原创 LeetCode Single Number XOR
int singleNumber(int* nums, int numsSize) { int p=nums[0]; for(int i=1;i<numsSize;i++) { p^=nums[i]; } return p;}这是根据论坛上的XOR(异或)方式写的答案。^是C语言的位运算符,按位异或的意思.a^b就是拿a和
2016-01-29 11:39:00 290
原创 LeetCode Nim Game
bool canWinNim(int n) { return n%4==0?false:true;}一行C语言版,纯自己想出来的。这道题难点在于,不好想规律,想出规律得心应手。2016/1/29
2016-01-29 09:41:09 179
原创 LeetCode Same Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */bool isSameTree(struct TreeNode* p, struct TreeNod
2016-01-28 23:29:31 219
原创 LeetCode Move Zeroes
void moveZeroes(int* nums, int numsSize) { int rec=0,i; for(i=0;i<numsSize;i++) { if(nums[i]==0){ rec++; } else { nums[i-rec]=nums[
2016-01-28 17:14:14 216
原创 LeeCode Invert Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */struct TreeNode* invertTree(struct TreeNode* r
2016-01-28 16:47:06 271
原创 LeetCode vDelete Node in a Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */void deleteNode(struct ListNode* node) { struct ListNode* first=node->next;
2016-01-28 16:20:38 293
原创 LeetCode Maximum Depth of Binary tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */int maxDepth(struct TreeNode* root) { int Dlef
2016-01-28 15:46:14 261
原创 LeetCode AddDigits
int addDigits(int num) { if(num>9) { num=num%10+addDigits(num/10); addDigits(num); } else return num;}递归算法。2016年1月28日想法。
2016-01-28 12:42:20 328
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人