Skip to content

Commit 2120a8b

Browse files
committed
style: code block syntax 적용
1 parent 377bd1d commit 2120a8b

File tree

4 files changed

+77
-77
lines changed

4 files changed

+77
-77
lines changed

climbing-stairs/invidam.go.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ DP has two methods: tabulation and memoization. I'll introduce both methods.
2424

2525
(n is value of `n`)
2626
# Code
27-
```
27+
```go
2828
func climbStairsV1(n int) int {
29-
climbData := make([]int, n+2, n+2)
30-
climbData[0], climbData[1] = 1, 1
31-
for s := 0; s < n; s++ {
32-
climbData[s+2] = climbData[s] + climbData[s+1]
33-
}
29+
climbData := make([]int, n+2, n+2)
30+
climbData[0], climbData[1] = 1, 1
31+
for s := 0; s < n; s++ {
32+
climbData[s+2] = climbData[s] + climbData[s+1]
33+
}
3434

35-
return climbData[n]
35+
return climbData[n]
3636
}
3737

3838
func climbStairsV2(n int) int {
39-
prev, curr := 1, 1
40-
for s := 1; s < n; s++ {
41-
prev, curr = curr, prev + curr
42-
}
39+
prev, curr := 1, 1
40+
for s := 1; s < n; s++ {
41+
prev, curr = curr, prev+curr
42+
}
4343

44-
return curr
44+
return curr
4545
}
4646
```
4747

@@ -65,7 +65,7 @@ func climbStairsV2(n int) int {
6565
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
6666
(n is value of `n`)
6767
# Code
68-
```
68+
```go
6969
var cache map[int]int = map[int]int{}
7070
func climbStairs(n int) int {
7171
if n == 0 || n == 1 {

maximum-depth-of-binary-tree/invidam.go.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@ Implement Queue can be troublesome, but it is effective to problem that require
4848
# Code
4949
```
5050
func maxDepth(root *TreeNode) int {
51-
if root == nil {
52-
return 0
53-
}
54-
depth := 0
55-
currLevel := []*TreeNode{root}
56-
57-
for len(currLevel) != 0 {
58-
depth++
59-
for _, curr := range currLevel {
60-
if curr.Left != nil {
61-
currLevel = append(currLevel, curr.Left)
62-
}
63-
if curr.Right != nil {
64-
currLevel = append(currLevel, curr.Right)
65-
}
66-
currLevel = currLevel[1:]
67-
}
68-
}
51+
if root == nil {
52+
return 0
53+
}
54+
depth := 0
55+
currLevel := []*TreeNode{root}
56+
57+
for len(currLevel) != 0 {
58+
depth++
59+
for _, curr := range currLevel {
60+
if curr.Left != nil {
61+
currLevel = append(currLevel, curr.Left)
62+
}
63+
if curr.Right != nil {
64+
currLevel = append(currLevel, curr.Right)
65+
}
66+
currLevel = currLevel[1:]
67+
}
68+
}
6969
70-
return depth
70+
return depth
7171
}
7272
```
7373

same-tree/invidam.go.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Recursion is natural method to iterate trees. (Particularly, multiple trees!)
1616

1717
(n and m are number of nodes in trees p and q. $$h_n$$ and $$h_m$$ are their heights.)
1818
# Code
19-
```
19+
```go
2020
func isSameTree(p *TreeNode, q *TreeNode) bool {
21-
if p == nil || q == nil {
22-
return p == nil && q == nil
23-
}
21+
if p == nil || q == nil {
22+
return p == nil && q == nil
23+
}
2424

25-
return p.Val == q.Val && isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right)
25+
return p.Val == q.Val && isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right)
2626
}
2727
```
2828
- - -
@@ -40,7 +40,7 @@ func isSameTree(p *TreeNode, q *TreeNode) bool {
4040

4141
(n and m are number of nodes in trees p and q.)
4242
# Code
43-
```
43+
```go
4444
func updateQueue(node *TreeNode, queue []*TreeNode) []*TreeNode {
4545
queue = append(queue, node.Left)
4646
queue = append(queue, node.Right)

subtree-of-another-tree/invidam.go.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,58 +48,58 @@ func isSubtree(root *TreeNode, subRoot *TreeNode) bool {
4848
(This complexity is determined. because the maximun sizes of the queues (`q`, `q1`, `q2`), which doesn't exceed the sum of sizes of both trees.)
4949
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
5050
# Code
51-
```
51+
```go
5252
func isEqualTree(root *TreeNode, subRoot *TreeNode) bool {
53-
q1 := []*TreeNode{root}
54-
q2 := []*TreeNode{subRoot}
53+
q1 := []*TreeNode{root}
54+
q2 := []*TreeNode{subRoot}
5555

56-
for len(q1) != 0 {
57-
f1 := q1[0]
58-
f2 := q2[0]
56+
for len(q1) != 0 {
57+
f1 := q1[0]
58+
f2 := q2[0]
5959

60-
q1 = q1[1:]
61-
q2 = q2[1:]
60+
q1 = q1[1:]
61+
q2 = q2[1:]
6262

63-
if (f1 == nil) && (f2 == nil) {
64-
continue
65-
}
66-
if (f1 == nil) || (f2 == nil) || (f1.Val != f2.Val) {
67-
return false
68-
}
63+
if (f1 == nil) && (f2 == nil) {
64+
continue
65+
}
66+
if (f1 == nil) || (f2 == nil) || (f1.Val != f2.Val) {
67+
return false
68+
}
6969

70-
q1 = append(q1, f1.Left)
71-
q1 = append(q1, f1.Right)
70+
q1 = append(q1, f1.Left)
71+
q1 = append(q1, f1.Right)
7272

73-
q2 = append(q2, f2.Left)
74-
q2 = append(q2, f2.Right)
75-
}
76-
77-
return true
73+
q2 = append(q2, f2.Left)
74+
q2 = append(q2, f2.Right)
75+
}
76+
77+
return true
7878
}
7979

8080
func isSubtree(root *TreeNode, subRoot *TreeNode) bool {
81-
if root == nil {
82-
//assert subRoot != nil
83-
return false
84-
}
81+
if root == nil {
82+
//assert subRoot != nil
83+
return false
84+
}
8585

86-
q := []*TreeNode{root}
86+
q := []*TreeNode{root}
8787

88-
for len(q) != 0 {
89-
node := q[0]
90-
q = q[1:]
88+
for len(q) != 0 {
89+
node := q[0]
90+
q = q[1:]
9191

92-
if node == nil {
93-
continue
94-
}
95-
if isEqualTree(node, subRoot) {
96-
return true
97-
}
92+
if node == nil {
93+
continue
94+
}
95+
if isEqualTree(node, subRoot) {
96+
return true
97+
}
9898

99-
q = append(q, node.Left)
100-
q = append(q, node.Right)
101-
}
99+
q = append(q, node.Left)
100+
q = append(q, node.Right)
101+
}
102102

103-
return false
103+
return false
104104
}
105105
```

0 commit comments

Comments
 (0)