Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8eca8c9

Browse files
authored
Merge branch 'main' into main
2 parentsf51f5b7 +cb98925 commit8eca8c9

File tree

84 files changed

+1984
-113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1984
-113
lines changed

‎.github/workflows/stale.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
repo-token:${{ secrets.GITHUB_TOKEN }}
2525
stale-issue-message:'Stale issue message'
2626
stale-pr-message:'Stale pull request message'
27-
stale-issue-label:'no-issue-activity'
28-
stale-pr-label:'no-pr-activity'
27+
stale-issue-label:'stale'
28+
stale-pr-label:'stale'
2929
days-before-stale:30
3030
days-before-close:7
31-
days-before-issue-stale:90
31+
days-before-issue-stale:900
3232
exempt-milestones:true
3333
exempt-pr-labels:'pending'

‎README.md‎

Lines changed: 57 additions & 57 deletions
Large diffs are not rendered by default.

‎c/108-Convert-Sorted-Array.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Given an integer array nums where the elements are sorted in
3+
ascending order, convert it to a height-balanced binary search tree.
4+
5+
Space: O(n)
6+
Time: O(n)
7+
*/
8+
9+
structTreeNode*dichomoty_rec(int*nums,inti,intj) {
10+
if (i>j)
11+
returnNULL;
12+
structTreeNode*new_t=malloc(sizeof(structTreeNode));
13+
intm= (i+j)/2;
14+
new_t->val=nums[m];
15+
new_t->left=dichomoty_rec(nums,i,m-1);
16+
new_t->right=dichomoty_rec(nums,m+1,j);
17+
returnnew_t;
18+
}
19+
20+
structTreeNode*sortedArrayToBST(int*nums,intnumsSize){
21+
returndichomoty_rec(nums,0,numsSize-1);
22+
}

‎c/112-Path-Sum.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
Given the root of a binary tree and an integer targetSum, return true
3+
if the tree has a root-to-leaf path such that adding up all the values
4+
along the path equals targetSum.
5+
6+
Space: O(log(n)) (due to recursive calls)
7+
Time: O(n)
8+
*/
9+
10+
boolhasPathSum(structTreeNode*root,inttargetSum){
11+
if (!root)
12+
return false;
13+
if (!root->left&& !root->right)
14+
returnroot->val==targetSum;
15+
returnhasPathSum(root->left,targetSum-root->val)||hasPathSum(root->right,targetSum-root->val);
16+
}

‎c/118-Pascals-Triangle.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Given an integer numRows, return the first numRows of Pascal's triangle.
3+
4+
Space: O(n²) (n=numRows)
5+
Time: O(n²)
6+
*/
7+
8+
int**generate(intnumRows,int*returnSize,int**returnColumnSizes){
9+
*returnSize=numRows;
10+
(*returnColumnSizes)=malloc(sizeof(int*)*numRows);
11+
int**ans=malloc(sizeof(int*)*numRows);
12+
for (inti=0;i<numRows;i++) {
13+
(*returnColumnSizes)[i]=i+1;
14+
ans[i]=malloc(sizeof(int)*(i+1));
15+
ans[i][0]=1;
16+
ans[i][i]=1;
17+
}
18+
for (inti=2;i<numRows;i++) {
19+
for (intj=1;j<i;j++) {
20+
ans[i][j]=ans[i-1][j-1]+ans[i-1][j];
21+
}
22+
}
23+
returnans;
24+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
3+
4+
Space: O(1)
5+
Time: O(n)
6+
*/
7+
8+
9+
intmin(inta,intb) {
10+
returna<b?a:b;
11+
}
12+
13+
intmaxNumberOfBalloons(char*text){
14+
// Counter for each letter
15+
intb=0;
16+
inta=0;
17+
intl=0;
18+
into=0;
19+
intn=0;
20+
for (inti=0;text[i]!='\0';i++) {
21+
if (text[i]=='b') {
22+
b++;
23+
}elseif (text[i]=='a') {
24+
a++;
25+
}elseif (text[i]=='l') {
26+
l++;
27+
}elseif (text[i]=='o') {
28+
o++;
29+
}elseif (text[i]=='n') {
30+
n++;
31+
}
32+
}
33+
l /=2;// There is 2 'l' in balloon
34+
o /=2;// There is 2 'o' in balloon
35+
returnmin(b,min(a,min(l,min(o,n))));
36+
}

‎c/129-Sum-Root-To-Leaf.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Return the total sum of all root-to-leaf numbers.
3+
4+
Space: O(1)
5+
Time: O(n)
6+
*/
7+
8+
intdfs(structTreeNode*r,intacc) {
9+
if (r==NULL)
10+
returnacc;
11+
if (r->left==NULL&&r->right==NULL)
12+
returnacc*10+r->val;
13+
if (r->left==NULL)
14+
returndfs(r->right,acc*10+r->val);
15+
if (r->right==NULL)
16+
returndfs(r->left,acc*10+r->val);
17+
returndfs(r->right,acc*10+r->val)+dfs(r->left,acc*10+r->val);
18+
}
19+
20+
intsumNumbers(structTreeNode*root){
21+
returndfs(root,0);
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.
3+
4+
Space: O(1)
5+
Time: O(n)
6+
*/
7+
8+
intmax(inta,intb) {
9+
returna>b?a:b;
10+
}
11+
12+
int*replaceElements(int*arr,intarrSize,int*returnSize){
13+
intgreatest=-1;
14+
*returnSize=arrSize;
15+
for (inti=arrSize-1;i>=0;i--) {
16+
intm=greatest;
17+
greatest=max(greatest,arr[i]);
18+
arr[i]=m;
19+
}
20+
returnarr;
21+
}

‎c/169-Majority-Element.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Given an array nums of size n, return the majority element.
3+
4+
Space: O(1)
5+
Time: O(n)
6+
*/
7+
8+
intmajorityElement(int*nums,intnumsSize){
9+
intcandidate=nums[0];
10+
intcount=1;
11+
for (inti=1;i<numsSize;i++) {
12+
if (candidate==nums[i]) {
13+
count++;
14+
}else {
15+
count--;
16+
if (count==0) {
17+
count=1;
18+
candidate=nums[i];
19+
}
20+
}
21+
}
22+
returncandidate;
23+
}

‎c/1905-Count-Sub-Islands.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
3+
Space: O(n²) (due to recursives calls)
4+
Time: O(n²)
5+
*/
6+
7+
booldfs_test(int**grid1,int**grid2,inti,intj,intn,intm) {
8+
// Test if the island in grid2 is entirely in grid1 and delete the island in grid2
9+
boolans= (grid1[i][j]==1);
10+
grid2[i][j]=0;
11+
if (i>0&&grid2[i-1][j]==1)
12+
ans=dfs_test(grid1,grid2,i-1,j,n ,m)&&ans;
13+
if (j>0&&grid2[i][j-1]==1)
14+
ans=dfs_test(grid1,grid2,i,j-1,n ,m)&&ans;
15+
if (i<(n-1)&&grid2[i+1][j]==1)
16+
ans=dfs_test(grid1,grid2,i+1,j,n ,m)&&ans;
17+
if (j<(m-1)&&grid2[i][j+1]==1)
18+
ans=dfs_test(grid1,grid2,i,j+1,n ,m)&&ans;
19+
returnans;
20+
}
21+
22+
intcountSubIslands(int**grid1,intgrid1Size,int*grid1ColSize,int**grid2,intgrid2Size,int*grid2ColSize){
23+
intcpt=0;
24+
for (inti=0;i<grid1Size;i++) {
25+
for (intj=0;j<grid1ColSize[i];j++) {
26+
if (grid2[i][j]==1) {
27+
// Test if the island in grid2 is contained in an island in grid1
28+
if (dfs_test(grid1,grid2,i,j,grid1Size,grid1ColSize[i])){
29+
cpt++;
30+
}
31+
}
32+
}
33+
}
34+
returncpt;
35+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp