01 2021 档案

摘要:#define max(a,b) ((a)>(b))?(a):(b) int integerBreak(int n){ int dp[58]={0}, i, j; dp[1]=1; for(i=2; i<=n; i++){ for (j=1; j<=i/2; j++){ dp[i]= max( dp 阅读全文
posted @ 2021-01-28 18:08 温暖了寂寞 阅读(65) 评论(0) 推荐(0)
摘要:bool increasingTriplet(int* nums, int numsSize){ int max=nums[0], min=nums[0], i, cnt=1; for(i=1; i<numsSize && cnt<3; i++){ if(nums[i]>max){ cnt++; m 阅读全文
posted @ 2021-01-24 12:08 温暖了寂寞 阅读(93) 评论(0) 推荐(0)
摘要:struct st { int pre; int prepre; }; #define max(a,b) ((a)>(b))?(a):(b) struct st recursion(struct TreeNode* root){ if(!root){ return (struct st){0,0}; 阅读全文
posted @ 2021-01-24 11:51 温暖了寂寞 阅读(67) 评论(0) 推荐(0)
摘要:void wiggleSort(int* nums, int numsSize){ int hash[5001]={0}, i, j=0; for(i=0; i<numsSize; i++) hash[nums[i]]++; i=(numsSize%2)?numsSize-1 :numsSize-2 阅读全文
posted @ 2021-01-24 11:33 温暖了寂寞 阅读(60) 评论(0) 推荐(0)
摘要:int cmp(const void* a, const void* b){ return *(int*)b - *(int*)a; } void recursion(int* coins,int coinsSize,int amount,int cur,int sum,int cnt,int* m 阅读全文
posted @ 2021-01-22 20:39 温暖了寂寞 阅读(91) 评论(0) 推荐(0)
摘要:/*只有完全平方数的因数数量是奇数,奇数灯亮,偶数灯灭*/ int bulbSwitch(int n){ return sqrt(n); } 阅读全文
posted @ 2021-01-22 11:17 温暖了寂寞 阅读(80) 评论(0) 推荐(0)
摘要:#define INT_MAX 2147483647 int nthSuperUglyNumber(int n, int* primes, int primesSize){ if(n == 1) return 1; int *res = (int *)calloc(n, sizeof(int)); 阅读全文
posted @ 2021-01-20 14:52 温暖了寂寞 阅读(92) 评论(0) 推荐(0)
摘要:char* removeDuplicateLetters(char* s) { int vis[26], num[26]; memset(vis, 0, sizeof(vis)); memset(num, 0, sizeof(num)); int n = strlen(s); for (int i 阅读全文
posted @ 2021-01-15 20:47 温暖了寂寞 阅读(103) 评论(0) 推荐(0)
摘要:int hIndex(int* citations, int citationsSize){ if(citationsSize==0) return 0; int i,cnt=0; for(i=citationsSize-1; i>=0 && citations[i]>0 && citationsS 阅读全文
posted @ 2021-01-08 21:38 温暖了寂寞 阅读(52) 评论(0) 推荐(0)
摘要:#define min(a,b) ((a)<(b))?(a):(b) int nthUglyNumber(int n){ int nums[1691] = {0}; nums[0]=1; int ugly, i2 = 0, i3 = 0, i5 = 0; for(int i = 1; i < n; 阅读全文
posted @ 2021-01-07 19:21 温暖了寂寞 阅读(82) 评论(0) 推荐(0)
摘要:class Solution: def singleNumber(self, nums: int) -> List[int]: # difference between two numbers (x and y) which were seen only once bitmask = 0 for n 阅读全文
posted @ 2021-01-06 23:36 温暖了寂寞 阅读(68) 评论(0) 推荐(0)
摘要:bool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target){ int row = matrixSize-1; int col = 0; while (row >= 0 && col < *matrix 阅读全文
posted @ 2021-01-06 15:57 温暖了寂寞 阅读(58) 评论(0) 推荐(0)
摘要:class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { int length = nums.size(); vector<int> answer(length); // answer[i] 表示索引 i 阅读全文
posted @ 2021-01-04 00:18 温暖了寂寞 阅读(64) 评论(0) 推荐(0)
摘要:struct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) { if(root==p || root==q || !root) return root; st 阅读全文
posted @ 2021-01-03 16:48 温暖了寂寞 阅读(64) 评论(0) 推荐(0)
摘要:int recursion(struct TreeNode* root, int* k,int* ret){ if(!root || *k==0) return *ret; recursion(root->left,k,ret); if(--(*k)==0){ *ret = root->val; } 阅读全文
posted @ 2021-01-03 11:48 温暖了寂寞 阅读(55) 评论(0) 推荐(0)
摘要:#define max(a,b) ((a)>(b))?(a) :(b); int maxProfit(int* prices, int pricesSize){ if(pricesSize==0) return 0; int i, buy=-prices[0], sell=0, pre=0, tmp 阅读全文
posted @ 2021-01-02 16:27 温暖了寂寞 阅读(68) 评论(0) 推荐(0)
摘要:bool isAdditiveNumber(char * num){ int i, j, k, len=strlen(num), pst1=0, pst2=0, bit=0, third; char* tmp1=(char*)calloc(22,sizeof(char)); char* tmp2=( 阅读全文
posted @ 2021-01-01 22:21 温暖了寂寞 阅读(105) 评论(0) 推荐(0)