摘要:int minNumber(int* nums1, int nums1Size, int* nums2, int nums2Size) { int min=INT_MAX; for(int i=0;i<nums1Size;i++){ int sum=0; for(int j=0;j<nums2Siz
阅读全文
摘要:int count; void dfs(int* nums,int numsSize,int diff,int index,int pre,int nowcount){ if(index>numsSize || nowcount>3) return; if(index==numsSize && no
阅读全文
摘要:int sumOfMultiples(int n){ int* dp=(int*)malloc(sizeof(int)*(n+4)); dp[1]=0,dp[2]=0; for(int i=3;i<=n;i++){ if(i%3==0 || i%5==0 || i%7==0 ){ dp[i]=dp[
阅读全文
摘要:int numberOfEmployeesWhoMetTarget(int* hours, int hoursSize, int target){ int count=0; for(int i=0;i<hoursSize;i++){ if(hours[i] >= target) count++; }
阅读全文
摘要:int findKOr(int* nums, int numsSize, int k) { if(k>numsSize) return 0; int sum=0; for(int i=0;i<31;i++){ int count=0; for(int j=0;j<numsSize;j++){ int
阅读全文
摘要:int cmp(const void* a,const void* b){ return *(int*)a-*(int*)b; } int distinctAverages(int* nums, int numsSize) { if(numsSize <=2) return 1; qsort(num
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:bool judge(char c){ if(c>='a'&& c<='z' || c>='A' && c<='Z' || c>='0' && c<='9' ) return true; return false; } bool isPalindrome(char* s) { int n=strle
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* pre; bool judge(struct ListN
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ void reverse(int* s,int n){ int head=0,tail=n-1; while(head<=tail){ in
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } void reverse(char* s,int head,int tail){ while(head<=tail){ char c=s[head]; s[head]=s[tail]; s[tai
阅读全文
摘要:bool judge(char* s1,char* s2,int n){ for(int i=0;i<n;i++){ if(s1[i]!=s2[i]) return false; } return true; } char* longestCommonPrefix(char** strs, int
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } int maxProfit(int* prices, int pricesSize) { int** dp=(int**)malloc(sizeof(int*)*pricesSize); for(
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ char temp[10]; char c[10][5]={" "," ","abc","def","ghi","jkl","mno","p
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* bu
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* tr
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* le
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* lo
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ long pre; bool inor
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * Note: The ret
阅读全文
摘要:int findMaxConsecutiveOnes(int* nums, int numsSize) { int max=0,index=0,count=0; while(index<numsSize){ if(nums[index]==1){ count++; if(count>max) max
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* middleNode(struct ListNode*
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* co
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ int divide(int* stock,int head,int tail){ int t=stock[head]; while(hea
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int min(int i,int j
阅读全文
摘要:/** * Definition for a Node. * struct Node { * int val; * int numChildren; * struct Node** children; * }; */ int maxDepth(struct Node* root) { if(!roo
阅读全文
摘要:int min; void dfs(char* s,int head,int tail, int count){ if(head>=tail){ if(count<min) min=count; return ; } if(s[head]==s[tail]){ dfs(s,head+1,tail-1
阅读全文
摘要:int visit[300][300]; void dfs(char** grid,int m,int n,int i,int j){ if(i>=m || j>=n) return; visit[i][j]=1; if( i+1<m && grid[i+1][j]=='1' && visit[i+
阅读全文
摘要:] 不简单的题目。 char change(int n){ if(n<=9) return n+'0'; return n-10+'a'; } void reverse(char* array,int n){ int head=0,tail=n-1; while(head<=tail){ char
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * Return an arr
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ typedef struct node{ int num; int count; }HASH; void insert(HASH* h,in
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:void reverse(char* num1, int n){ int head=0,tail=n-1; while(head<=tail){ char c=num1[head]; num1[head]=num1[tail]; num1[tail]=c; head++; tail--; } } i
阅读全文
摘要:int f(int a ,int b,char c){ if(c=='+') return a+b; if(c=='-') return a-b; if(c=='/') return a/b; return a*b; } int evalRPN(char** tokens, int tokensSi
阅读全文
摘要:void build(int* next,char* s,int n){ next[0]=-1; int index=1,j=-1; while(index<n){ if(j 1 || s[index-1] == s[j]){ j++; next[index++]=j; }else{ j=next[
阅读全文
摘要:void bulid(int* next,char* s,int n){ next[0]=-1; int index=1,j=-1; while(index<n){ if(j 1 || s[index-1] ==s[j] ){ j++; next[index++]=j; }else{ j=next[
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode *detectCycle(struct ListNode
阅读全文
摘要:bool judge(int* s,int* t){ for(int i=0;i<200;i++){ if(s[i]<t[i]) return false; } return true; } char* minWindow(char* s, char* t) { int ns=strlen(s),n
阅读全文
摘要:int totalFruit(int* fruits, int fruitsSize) { int lanzi[2]={-1,-1}; if(fruitsSize<=2) return fruitsSize; int max=0,count=0; int head=0,tail=0; while(t
阅读全文
摘要:int minSubArrayLen(int target, int* nums, int numsSize) { int head=0,tail=0,sum=nums[0]; long min=LONG_MAX; while(tail<numsSize){ if(sum>=target){ if(
阅读全文
摘要:bool backspaceCompare(char* s, char* t) { int ns=strlen(s),nt=strlen(t); int heads=0,headt=0,index=0; while(index<ns){ if(s[index]!='#'){ s[heads++]=s
阅读全文
摘要:int removeDuplicates(int* nums, int numsSize) { int head=0,index=0; while(index<numsSize){ if(index!=0 && nums[index]!=nums[index-1]){ nums[head++]=nu
阅读全文
摘要:bool isPerfectSquare(int num) { if(num==1) return true; int head=0,tail=num-1; while(head<=tail){ int mid=head+(tail-head)/2; long long temp=pow(mid,2
阅读全文
摘要:int searchInsert(int* nums, int numsSize, int target) { int head=0,tail=numsSize-1; while(head<=tail){ int mid=head+(tail-head)/2; if(nums[mid]==targe
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ bool judge(int* a,int* b){ for(int i=0;i<27;i++){ if(a[i]<b[i]) return
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:void moveZeroes(int* nums, int numsSize) { int head=0,index=0; while(index<numsSize){ if(nums[index]!=0){ nums[head++]=nums[index]; } index++; } for(;
阅读全文
摘要:void build(char* s,int* next,int n){ next[0]=-1; int i=1,j=-1; while(i<n){ if(j 1||s[j]==s[i-1]){ next[i]=j+1; j++; i++; }else{ j=next[j]; } } for(int
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> int max(int i,int j){ if(i>j) return i; return j; } int main(){ int m,n; scanf("%d %d\n",&m,&n); int* value=(int*
阅读全文
摘要:int numTrees(int n) { int* dp=(int*)malloc(sizeof(int)*(n+4)); for(int i=0;i<n+4;i++) dp[i]=0; dp[0]=1,dp[1]=1,dp[2]=2; for(int i=3;i<=n;i++){ for(int
阅读全文
摘要:int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridSize, int* obstacleGridColSize) { if(obstacleGridSize==0) return 0; int m=obstacleGri
阅读全文
摘要:int uniquePaths(int m, int n) { int** dp=(int**)malloc(sizeof(int*)*m); for(int i=0;i<m;i++) dp[i]=(int*)malloc(sizeof(int)*n); for(int i=0;i<m;i++) d
阅读全文
摘要:int climbStairs(int n) { int* dp=(int*)malloc(sizeof(int)*(n+4)); dp[0]=1,dp[1]=1; for(int i=2;i<=n;i++){ dp[i]=dp[i-1]+dp[i-2]; } return dp[n]; }
阅读全文
摘要:int fib(int n){ int* dp=(int*)malloc(sizeof(int)*(n+4)); dp[0]=0,dp[1]=1; for(int i=2;i<=n;i++){ dp[i]=dp[i-1]+dp[i-2]; } return dp[n]; }
阅读全文
摘要:typedef struct node{ int left; int right; }bounds; int cmp(const void* a,const void* b){ bounds* x=(bounds*)a; bounds* y=(bounds*)b; if(x->right > y->
阅读全文
摘要:typedef struct node{ int left; int right; }bounds; int cmp(const void* a,const void* b){ bounds* x=(bounds*)a; bounds* y=(bounds*)b; if(x->right >y->r
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:bool lemonadeChange(int* bills, int billsSize) { int money[21]={0}; for(int i=0;i<billsSize;i++){ if(bills[i]==5){ money[5]++; }else if(bills[i]==10){
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } int candy(int* ratings, int ratingsSize) { int* left=(int*)malloc(sizeof(int)*ratingsSize); int* r
阅读全文
摘要:int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize) { int sum=0,n=gasSize; for(int i=0;i<n;i++){ gas[i]=gas[i]-cost[i]; sum+=gas[i]
阅读全文
摘要:int largestSumAfterKNegations(int* nums, int numsSize, int k) { int t[201]={0}; int sum=0; for(int i=0;i<numsSize;i++){ sum+=nums[i]; t[nums[i]+100]++
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } bool canJump(int* nums, int numsSize) { if(numsSize==1) return true; if(nums[0]==0) return false;
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } int maxProfit(int* prices, int pricesSize) { int** dp=(int**)malloc(sizeof(int*)*pricesSize); for(
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } int maxSubArray(int* nums, int numsSize) { int* dp=(int*)malloc(sizeof(int)*numsSize); dp[0]=nums[
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } int wiggleMaxLength(int* nums, int numsSize){ int** dp=(int**)malloc(sizeof(int*)*numsSize); for(i
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:\ bool isUnique(char* astr){ int temp[26]={0}; for(int i=0;i<strlen(astr);i++){ temp[astr[i]-'a']++; } for(int i=0;i<26;i++){ if(temp[i]>1) return fal
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ bool hasCycle(struct ListNode *head) { struct
阅读全文
摘要:回文串 置逆,栈,双指针。 bool judge(char c){ if(c>='a'&&c<='z') return true; if(c>='A'&&c<='Z') return true; if(c>='0'&&c<='9') return true; return false; } bool
阅读全文
摘要:int singleNumber(int* nums, int numsSize) { int t=nums[0]; for(int i=1;i<numsSize;i++) t=t^nums[i]; return t; } 结果:
阅读全文
摘要:int sum(int num1, int num2){ return num1+num2; }
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* pre; bool judge(struct ListN
阅读全文
摘要:char findTheDifference(char* s, char* t) { int temps[26]={0}; int tempt[26]={0}; int n1=strlen(s),n2=strlen(t); for(int i=0;i<n1;i++) temps[s[i]-'a']+
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ void reverse(int* a,int n){ int head=0,tail=n-1; while(head<=tail){ in
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ int pre; struct ListNode* f(struct ListNode*
阅读全文
摘要:特好的题目,进制转化就刷它。 void reverse(char* s){ int n=strlen(s); int head=0,tail=n-1; while(head<=tail){ char t=s[head]; s[head]=s[tail]; s[tail]=t; head++; tai
阅读全文
摘要:int cmp(const void* a,const void* b){ return *(int*)a-*(int*)b; } int majorityElement(int* nums, int numsSize) { qsort(nums,numsSize,sizeof(int),cmp);
阅读全文
摘要:bool isPalindrome(int x) { char c[1000]={0}; sprintf(c,"%d",x); int n=strlen(c); int head=0,tail=n-1; while(head<=tail){ if(c[head]!=c[tail]) return f
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* mergeTwoLists(struct ListNod
阅读全文
摘要:char* longestCommonPrefix(char** strs, int strsSize) { int index=1,min=INT_MAX; if(strsSize==1) return strs[0]; while(index<strsSize){ int i=0; while(
阅读全文
摘要:int romanToInt(char* s) { int n=strlen(s); int c[26]; c['I'-'A']=1; c['V'-'A']=5; c['X'-'A']=10; c['L'-'A']=50; c['C'-'A']=100; c['D'-'A']=500; c['M'-
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } int maxProfit(int* prices, int pricesSize) { int** dp=(int**)malloc(sizeof(int*)*pricesSize); for(
阅读全文
摘要:char * mergeAlternately(char * word1, char * word2){ int n1=strlen(word1),n2=strlen(word2); char* temp=(char*)malloc(sizeof(char)*(n1+n2+1)); int inde
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:脑残了,参数传错了,debug了半天。 /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: B
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ char c[10][10]={" "," ","abc\0","def\0","ghi\0","jkl\0","mno\0","pqrs\
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* bu
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* tr
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* le
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* lo
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * Note: The ret
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool inorder(struct
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* me
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int findBottomLeftV
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int preorder(struct
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * Note: The ret
阅读全文
摘要:int tribonacci(int n){ int* dp=(int*)malloc(sizeof(int)*(n+4)); dp[0]=0,dp[1]=1,dp[2]=1; for(int i=3;i<=n;i++) dp[i]=dp[i-1]+dp[i-2]+dp[i-3]; return d
阅读全文
摘要:int findMaxConsecutiveOnes(int* nums, int numsSize) { int max=0,sum=0,index=0; while(index<numsSize){ if(nums[index]==1){ sum++; if(sum>max) max=sum;
阅读全文
摘要:这是很难得题目,标准解的二分查找,以后要掌握。 int stockManagement(int* stock, int stockSize) { int min=stock[0]; for(int i=1;i<stockSize;i++){ if(stock[i]<min) min=stock[i]
阅读全文
摘要:// The API isBadVersion is defined for you. // bool isBadVersion(int version); int firstBadVersion(int n) { int head=1,tail=n; if(isBadVersion(head))
阅读全文
摘要:树遍历的变形 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeN
阅读全文
摘要:经典快排 /** * Note: The returned array must be malloced, assume caller calls free(). */ int divide(int* a,int head,int tail){ int t=a[head]; while(head<t
阅读全文
摘要:void duplicateZeros(int* arr, int arrSize) { int* temp=(int*)malloc(sizeof(int)*arrSize); int head=0,index=0; while(head<arrSize && index<arrSize){ te
阅读全文
摘要:还有什么比刷简单题更爽的。 int cmp(const void* a,const void* b){ return *(int*)a-*(int*)b; } void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int min(int i,int j
阅读全文
摘要:/** * Definition for a Node. * struct Node { * int val; * int numChildren; * struct Node** children; * }; */ int maxDepth(struct Node* root) { if(!roo
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ typedef struct node{ int num; int count; }Hash; void inset(Hash* hash,
阅读全文
摘要:C语言没有优先队列库,如果自己实现的话在考试是不现实的。优先使用暴力简单的方法加稍微优化尽可能多的过例子。 /** * Note: The returned array must be malloced, assume caller calls free(). */ int findmax(int*
阅读全文
摘要:int cmp(int a,int b,char c){ if(c=='+') return a+b; if(c=='-') return a-b; if(c=='*') return a*b; return a/b; } int evalRPN(char** tokens, int tokensS
阅读全文
摘要:KMP! void buildnext(int* next,char* s){ int n=strlen(s); for(int i=0;i<n;i++){ next[i]=pre(s,i); printf("%d ",next[i]); } } int pre(char* s,int head){
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode *detectCycle(struct ListNode
阅读全文
摘要:bool judge(int* temps,int* tempt){ for(int i=0;i<200;i++){ if(temps[i]<tempt[i]) return false; } return true; } char* minWindow(char* s, char* t) { in
阅读全文
摘要:typedef struct node{ int fruit; int lastindex; }node; int totalFruit(int* fruits, int fruitsSize) { node f[2]; f[0].fruit=-1,f[1].fruit=-1; int max=0,
阅读全文
摘要:int minSubArrayLen(int target, int* nums, int numsSize) { int sum=nums[0],head=0,tail=0,min=INT_MAX; int t=0; for(int i=0;i<numsSize;i++){ t+=nums[i];
阅读全文
摘要:bool backspaceCompare(char* s, char* t) { int ns=strlen(s),nt=strlen(t); int head=0,tail=0; int n1=0,n2=0; while(tail<ns){ if(head==0&&s[tail]=='#'){
阅读全文
摘要:int removeDuplicates(int* nums, int numsSize) { int head=1,tail=1; int count=1; while(tail<numsSize){ if(nums[tail]!=nums[tail-1]){ nums[head++]=nums[
阅读全文
摘要:bool isPerfectSquare(int num) { if(num==1) return true; int head=1,tail=num-1; while(head<=tail){ int mid=(head+tail)/2; long smid=pow(mid,2); if(smid
阅读全文
摘要:int searchInsert(int* nums, int numsSize, int target) { int head=0,tail=numsSize-1; while(head<=tail){ int mid=(head+tail)/2; if(nums[mid] < target){
阅读全文
摘要:/** * Note: The returned array must be malloced, assume caller calls free(). */ int change(char c){ return c-'a'; } bool judge(char* s,int head,int ta
阅读全文
摘要:回溯写了个超时了。这里写得树层去重还是值得借鉴得。 /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * N
阅读全文
摘要:int maxArea(int* height, int heightSize) { int max=0; int head=0,tail=heightSize-1; while(head<tail){ int sum; if(height[head]<height[tail]){ sum=heig
阅读全文
摘要:void moveZeroes(int* nums, int numsSize) { int head=0,tail=0; while(tail<numsSize){ if(nums[tail]!=0){ nums[head++]=nums[tail++]; }else{ tail++; } } f
阅读全文
摘要:22号就要复试了,专业课,英语都还没搞,我的吗,先每天刷10道旧题在刷新题把。 int max(int i,int j){ if(i>j) return i; return j; } bool canPartition(int* nums, int numsSize) { int sum=0; fo
阅读全文
摘要:背包问题。 #include<stdio.h> #include<stdlib.h> int max(int i,int j){ if(i>j) return i; return j; } int main(){ int n1,n2; scanf("%d %d\n",&n1,&n2); int* v
阅读全文
摘要:int numTrees(int n) { int* dp=(int*)malloc(sizeof(int)*(n+3)); for(int i=0;i<n+3;i++) dp[i]=0; dp[0]=1,dp[1]=1; for(int i=2;i<=n;i++){ for(int j=1;j<=
阅读全文
摘要:关键就在于,分还是不分是个问题。 int max(int i,int j){ if(i>j) return i; return j; } int integerBreak(int n) { int* dp=(int*)malloc(sizeof(int)*(n+4)); dp[0]=0,dp[1]=
阅读全文
摘要:难点在初始化。 int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridSize, int* obstacleGridColSize) { if(obstacleGrid[0][0]==1) return 0; int m=o
阅读全文
摘要:int uniquePaths(int m, int n) { long** dp=(long**)malloc(sizeof(long*)*(m+10)); for(int i=0;i<m+10;i++) dp[i]=(long*)malloc(sizeof(long)*(n+3)); for(i
阅读全文
摘要:int min(int i,int j){ if(i<j) return i; return j; } int minCostClimbingStairs(int* cost, int costSize) { int* dp=(int*)malloc(sizeof(int)*(costSize+3)
阅读全文
摘要:还有什么比作对题且快更爽的呢。 int max(int i,int j){ if(i>j) return i; return j; } int climbStairs(int n) { int* dp=(int*)malloc(sizeof(int)*(n+3)); dp[0]=0,dp[1]=1,
阅读全文
摘要:贪心后面几道区间的题目写的我想吐。先写动态规划 int fib(int n){ int* t=(int*)malloc(sizeof(int)*(n+10)); t[0]=0,t[1]=1; for(int i=2;i<=n;i++){ t[i]=t[i-1]+t[i-2]; } return t[
阅读全文
摘要:折磨折磨,写错一个参数,找半天。 /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both
阅读全文
摘要:优先找10块,因为5块更重要。 bool lemonadeChange(int* bills, int billsSize) { int cash[21]={0}; for(int i=0;i<billsSize;i++){ if(bills[i]==5){ cash[5]++; }else if(
阅读全文
摘要:ji、 假设26号复试的话,只有15天复习了。 争取一个星期刷完代码随想录,最后一个星期来准备英语和重刷。 int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize) { int sum=0; int* oil=(in
阅读全文
摘要:int largestSumAfterKNegations(int* nums, int numsSize, int k) { int t[201]={0}; int sum=0; for(int i=0;i<numsSize;i++){ t[100+nums[i]]++; sum+=nums[i]
阅读全文
摘要:暴力DFS超时了。 先放着把。 int min; void dfs(int* nums,int numsSize,int index,int count){ if(index>=numsSize-1){ if(count <min) min=count; return ; } for(int i=n
阅读全文
摘要:动态规划实在让人上瘾啊,虽然过程很难想,但是代码实现实在太简单了。 int max(int i,int j){ if(i>j ) return i; return j; } bool canJump(int* nums, int numsSize) { if(numsSize==1 && nums[
阅读全文
摘要:、 动态规划太难啦! int getmax(int i,int j){ if(i>j) return i; return j; } int maxProfit(int* prices, int pricesSize) { if(pricesSize==1) return 0; int** dp=(i
阅读全文
摘要:int max(int i,int j){ if(i>j) return i; return j; } int maxSubArray(int* nums, int numsSize) { if(numsSize==1) return nums[0]; int* dp=(int*)malloc(si
阅读全文
摘要:动态规划yyds!虽然写不出来TT int max(int i,int j){ if(i>j) return i; return j; } int wiggleMaxLength(int* nums, int numsSize){ int dp[1000][2]={0};//dp[i][j] 表示到
阅读全文
摘要:int cmp(const void* a,const void* b){ return *(int*)a-*(int*)b; } int findContentChildren(int* g, int gSize, int* s, int sSize) { qsort(g,gSize,sizeof
阅读全文
摘要:\ 这题就是第一次做的时候,斜线没考虑清楚,有四个方向斜线。 /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array
阅读全文
摘要:我宣布我已经参透了套路,一次AC /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both
阅读全文
摘要:出息了!一次AC /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returne
阅读全文
摘要:复试的人真的搞心态啊,怎么能这么变态,刷题这么块。哭了。 要是难一点的重复问题还是写for循环好点。 /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *ret
阅读全文
摘要:非常好的题目,使我的大脑飞速旋转!! UP主代码随想录 结果:
阅读全文
摘要:leetcode官方解法实在是太绝了!!二刷的时候一定用上! /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array
阅读全文
摘要:、 leetcode调试功能真香啊,效率高了不少。但钱包也变扁了。。 /** * Note: The returned array must be malloced, assume caller calls free(). */ char temp[30]; int top=0; bool judg
阅读全文
摘要:这题真的坑爹啊,不明白为什么会产生万大小的数据啊。 /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * N
阅读全文
摘要:很好的题目,使我的大脑旋转。 /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both r
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:C语言字符串细节真多啊,搞了好久。 /** * Note: The returned array must be malloced, assume caller calls free(). */ char c[10][5]={" "," ","abc","def","ghi","jkl","mno"
阅读全文
摘要:/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a
阅读全文
摘要:回溯其实就是抽象图的遍历过程 这题数据实在太离谱了。 /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. *
阅读全文
摘要:右根左遍历就行。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ void order
阅读全文
摘要:如果按一般思路建一个平衡二叉树,非常麻烦。 但是二分查找树就一个平衡二叉树,所有构建二叉查找树就行。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; *
阅读全文
摘要:这题还是很难得。一看是想着当作普通二叉树所有节点都递归,但是很难做,难度很高。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct Tree
阅读全文
摘要:这题特别好,和递归删除链表里的元素有异曲同工之妙 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; *
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* in
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* pr
阅读全文
摘要:思想就是层次遍历,然后判断每个节点是否为父节点、 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; *
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ void inorder(struct
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool judge(struct T
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* se
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* me
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int maxindex(int* n
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* bu
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool judge(struct T
阅读全文
摘要:用的层序遍历 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int findBott
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ void postorder(stru
阅读全文
摘要:很好的题目,让我的sprintf旋转 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int max(int i,int j
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int countNodes(stru
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int min(int i,int j
阅读全文
摘要:/** * Definition for a Node. * struct Node { * int val; * int numChildren; * struct Node** children; * }; */ int maxDepth(struct Node* root) { if(!roo
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int max(int i,int j
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool issameroot(str
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool isSameTree(str
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool judge(struct T
阅读全文
摘要:层次遍历的题目C写吐血了,缓一缓再写那种气死人的题目。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right;
阅读全文
摘要:这题好像更新了呀,不压缩路径的话,find函数用递归的话会栈溢出。 #include <stdio.h> #include<stdbool.h> #include<stdlib.h> int set[101]; typedef struct node{ int length; int e1; int
阅读全文
摘要:要去寻找所有可能性,典型的dfs问题 #include<stdio.h> #include<stdlib.h> #include<stdbool.h> bool judge(int* temp,int* visit,int noweedge,int length,int n,int nowlengt
阅读全文
摘要:#include<stdio.h> void move(int tail,char now,char tool,char end,int n){//以nown为低,共 n个 if(n <=0) return; move(tail-1,now,end,tool,n-1); printf("%d:%c-
阅读全文
摘要:void reversestring(char* s,int head,int tail){ while(head<=tail){ char temp=s[head]; s[head]=s[tail]; s[tail]=temp; head++; tail--; } } char* reverseS
阅读全文
摘要:typedef struct node{ int sum; int count; struct node* repeatnext; }hash; void init_hash(hash* h){ for(int i=0;i<128;i++){ h[i].sum=0; h[i].count=0; h[
阅读全文
摘要:void reversestring(char* s,int head,int tail){ while(head<=tail){ char temp=s[head]; s[head]=s[tail]; s[tail]=temp; head++; tail--; } } char* reverseW
阅读全文