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

Commit08f16ad

Browse files
committed
add new files
1 parentb5ed682 commit08f16ad

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

‎566. Reshape the Matrix.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
funcmatrixReshape(nums [][]int,rint,cint) [][]int {
4+
ret:=make([][]int,r)
5+
fork:=rangeret {
6+
ret[k]=make([]int,c)
7+
}
8+
iflen(nums)==0||r*c!=len(nums)*len(nums[0]) {
9+
returnnums
10+
}
11+
rows,cols:=0,0
12+
fori:=0;i<len(nums);i++ {
13+
forj:=0;j<len(nums[0]);j++ {
14+
ret[rows][cols]=nums[i][j]
15+
cols++
16+
ifcols==c {
17+
rows++
18+
cols=0
19+
}
20+
}
21+
}
22+
returnret
23+
}

‎662. Maximum Width of Binary Tree.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
typeTreeNodestruct {
4+
Valint
5+
Left*TreeNode
6+
Right*TreeNode
7+
}
8+
9+
varansint
10+
varleftmap[int]int
11+
12+
funcwidthOfBinaryTree(root*TreeNode)int {
13+
ans=0
14+
left=make(map[int]int)
15+
dfs(root,0,0)
16+
returnans
17+
}
18+
funcdfs(root*TreeNode,depth,posint) {
19+
ifroot==nil {
20+
return
21+
}
22+
if_,ok:=left[depth];!ok {
23+
left[depth]=pos
24+
}
25+
ans=max(ans,pos-left[depth]+1)
26+
dfs(root.Left,depth+1,2*pos)
27+
dfs(root.Right,depth+1,2*pos+1)
28+
}
29+
30+
funcmax(x,yint)int {
31+
ifx>y {
32+
returnx
33+
}
34+
returny
35+
36+
}

‎766. Toeplitz Matrix.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
funcisToeplitzMatrix(matrix [][]int)bool {
4+
forr:=0;r<len(matrix);r++ {
5+
forc:=0;c<len(matrix[0]);c++ {
6+
ifr>0&&c>0&&matrix[r-1][c-1]!=matrix[r][c] {
7+
returnfalse
8+
}
9+
}
10+
}
11+
returntrue
12+
}

‎771. Jewels and Stones.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
funcnumJewelsInStones(Jstring,Sstring)int {
4+
jstr:= []byte(J)
5+
sstr:= []byte(S)
6+
m:=make(map[byte]bool)
7+
for_,v:=rangejstr {
8+
m[v]=true
9+
}
10+
num:=0
11+
for_,v:=rangesstr {
12+
if_,ok:=m[v];ok {
13+
num++
14+
}
15+
}
16+
returnnum
17+
}

‎867. Transpose Matrix.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
functranspose(A [][]int) [][]int {
4+
m:=len(A)
5+
n:=len(A[0])
6+
ans:=make([][]int,n)
7+
fork:=rangeans {
8+
ans[k]=make([]int,m)
9+
}
10+
forr:=0;r<m;r++ {
11+
forc:=0;c<n;c++ {
12+
ans[c][r]=A[r][c]
13+
}
14+
}
15+
returnans
16+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp