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

Commitde63f59

Browse files
committed
add new files
1 parent08f16ad commitde63f59

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
funclargestSumAfterKNegations(A []int,Kint)int {
4+
sum:=0
5+
forK>0 {
6+
small:=0
7+
fori:=0;i<len(A);i++ {
8+
ifA[i]<A[small] {
9+
small=i
10+
}
11+
}
12+
A[small]=A[small]*-1
13+
K--
14+
}
15+
for_,v:=rangeA {
16+
sum+=v
17+
}
18+
returnsum
19+
}

‎860. Lemonade Change.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
funclemonadeChange(bills []int)bool {
4+
m:=make([]int,2)
5+
fori:=0;i<len(bills);i++ {
6+
switchbills[i] {
7+
case5:
8+
m[0]++
9+
break
10+
case10:
11+
ifm[0]<=0 {
12+
returnfalse
13+
}
14+
m[0]--
15+
m[1]++
16+
break
17+
case20:
18+
flag:=false
19+
ifm[0]>=1&&m[1]>=1 {
20+
flag=true
21+
m[0]--
22+
m[1]--
23+
}elseifm[0]>=3 {
24+
flag=true
25+
m[0]-=3
26+
}
27+
if!flag {
28+
returnfalse
29+
}
30+
break
31+
}
32+
33+
}
34+
returntrue
35+
}

‎868. Binary Gap.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
funcbinaryGap(Nint)int {
4+
vard,maxint
5+
6+
ifN&(N-1)==0 {
7+
return0
8+
}
9+
10+
for ;N>0;N>>=1 {
11+
ifN&1==1 {
12+
ifmax==0 {
13+
max=1
14+
}
15+
ifd>max {
16+
max=d
17+
}
18+
d=0
19+
}
20+
ifmax>0 {
21+
d++
22+
}
23+
}
24+
returnmax
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp