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

Commit619ebf1

Browse files
authored
Merge pull requestneetcode-gh#1017 from Ykhan799/main
Create: 338-Counting-Bits.c, 11-Container-With-Most-Water.c, 70-Climbing-Stairs.c
2 parents786639e +5ffebc5 commit619ebf1

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

‎c/11-Container-With-Most-Water.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
intmaxArea(int*height,intheightSize){
2+
intleft=0;
3+
intright=heightSize-1;
4+
intres=0;
5+
6+
while (left<right) {
7+
res=max(res,min(height[left],height[right])* (right-left));
8+
if (height[left]<height[right]) {
9+
left+=1;
10+
}
11+
elseif (height[right] <=height[left]) {
12+
right-=1;
13+
}
14+
}
15+
returnres;
16+
}
17+
18+
// C does not have a predefined min and max function
19+
intmax(inta,intb) {
20+
return (a>b) ?a :b;
21+
}
22+
23+
intmin(inta,intb) {
24+
return (a<b) ?a :b;
25+
}

‎c/338-Counting-Bits.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Note: The returned array must be malloced, assume caller calls free().
3+
*/
4+
int*countBits(intn,int*returnSize){
5+
// Initialize array of size n + 1
6+
intarraySize=n+1;
7+
*returnSize=arraySize;
8+
int*dp= (int*)malloc(sizeof(int)*arraySize);
9+
memset(dp,0,arraySize*sizeof(dp[0]));
10+
intoffset=1;
11+
12+
// Perform dp
13+
for (inti=1;i <=n;i++) {
14+
if (offset*2==i) {
15+
offset=i;
16+
}
17+
dp[i]=1+dp[i-offset];
18+
}
19+
returndp;
20+
}

‎c/70-Climbing-Stairs.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
intclimbStairs(intn){
2+
if (n <=3) {
3+
returnn;
4+
}
5+
6+
intn1=2;
7+
intn2=3;
8+
9+
for (inti=4;i <=n;i++) {
10+
inttemp=n1+n2;
11+
n1=n2;
12+
n2=temp;
13+
}
14+
returnn2;
15+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp