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

Commit35bde91

Browse files
committed
add new files
1 parent4d8602f commit35bde91

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

‎71. Simplify Path.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import"strings"
4+
5+
funcsimplifyPath(pathstring)string {
6+
dirs:=strings.FieldsFunc(path,func(srune)bool {
7+
ifs=='/' {
8+
returntrue
9+
}
10+
returnfalse
11+
})
12+
fori:=0;i<len(dirs);i++ {
13+
ifdirs[i]=="." {
14+
dirs=append(dirs[:i],dirs[i+1:]...)
15+
i--
16+
}else {
17+
ifdirs[i]==".." {
18+
ifi==0 {
19+
dirs=dirs[1:]
20+
i--
21+
continue
22+
}
23+
dirs=append(dirs[:i-1],dirs[i+1:]...)
24+
i-=2
25+
}
26+
}
27+
}
28+
res:="/"
29+
fori:=0;i<len(dirs);i++ {
30+
res+=dirs[i]
31+
ifi!=len(dirs)-1 {
32+
res+="/"
33+
}
34+
}
35+
returnres
36+
}

‎79. Word Search.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
funchelp(b [][]byte,wordstring,i,jint)bool {
4+
ifword=="" {
5+
returntrue
6+
}
7+
ifb[i][j]!=word[0] {
8+
returnfalse
9+
}
10+
iflen(word)==1 {
11+
returntrue
12+
}
13+
b[i][j]='#'
14+
ifi>0&&help(b,word[1:],i-1,j) {
15+
returntrue
16+
}
17+
ifj>0&&help(b,word[1:],i,j-1) {
18+
returntrue
19+
}
20+
ifi<len(b)-1&&help(b,word[1:],i+1,j) {
21+
returntrue
22+
}
23+
ifj<len(b[0])-1&&help(b,word[1:],i,j+1) {
24+
returntrue
25+
}
26+
b[i][j]=word[0]
27+
returnfalse
28+
}
29+
funcexist(board [][]byte,wordstring)bool {
30+
iflen(board)==0||len(board[0])==0 {
31+
returnword==""
32+
}
33+
ifword=="" {
34+
returntrue
35+
}
36+
fori:=0;i<len(board);i++ {
37+
forj:=0;j<len(board[0]);j++ {
38+
ifword[0]!=board[i][j] {
39+
continue
40+
}
41+
ifhelp(board,word,i,j) {
42+
returntrue
43+
}
44+
}
45+
}
46+
returnfalse
47+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
funcsearch(nums []int,targetint)bool {
4+
l:=len(nums)
5+
ifl==0 {
6+
returnfalse
7+
}
8+
left,right:=0,l-1
9+
forleft<=right {
10+
mid:=left+ (right-left)/2
11+
ifnums[mid]==target {
12+
returntrue
13+
}elseifnums[mid]<nums[right] {
14+
ifnums[mid]<target&&nums[right]>=target {
15+
left=mid+1
16+
}else {
17+
right=mid-1
18+
}
19+
}elseifnums[mid]>nums[right] {
20+
ifnums[left]<=target&&nums[mid]>target {
21+
right=mid-1
22+
}else {
23+
left=mid+1
24+
}
25+
}else {
26+
right--
27+
}
28+
29+
}
30+
returnfalse
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp