Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
superj80820 committed May 16, 2024
1 parent 114a116 commit 90cb9a9
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 22 deletions.
25 changes: 18 additions & 7 deletions neetcode/0021-merge-two-sorted-lists.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: linked-list, star3, easy, practice-count:2
// tags: linked-list, star3, easy, practice-count:3

/**
* Definition for singly-linked list.
Expand All @@ -11,12 +11,6 @@
// space complexity: O(1)
// `n` is length of all node
func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
if list1 == nil {
return list2
} else if list2 == nil {
return list1
}

dummy := new(ListNode)

cur := dummy
Expand All @@ -38,4 +32,21 @@ func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
}

return dummy.Next
}

// time complexity: O(n)
// space complexity: O(n)
// `n` is length of all node
func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
if list1 == nil {
return list2
} else if list2 == nil {
return list1
}
if list1.Val <= list2.Val {
list1.Next = mergeTwoLists(list1.Next, list2)
return list1
}
list2.Next = mergeTwoLists(list2.Next, list1)
return list2
}
2 changes: 1 addition & 1 deletion neetcode/0042-trapping-rain-water.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: two-pointers, star3, hard, practice-count:2
// tags: two-pointers, star3, hard, practice-count:3

// time complexity: O(n)
// space complexity: O(1)
Expand Down
18 changes: 11 additions & 7 deletions neetcode/0070-climbing-stairs.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// tags: 1d-dp, star3, easy, practice-count:2
// tags: 1d-dp, star3, easy, practice-count:3

// time complexity: O(n)
// space complexity: O(1)
func climbStairs(n int) int {
n1, n2, n3 := 0, 0, 1
for i := 0; i < n; i++ {
n1 = n2
n2 = n3
n3 = n2 + n1
if n == 1 {
return 1
}
return n3
n1, n2 := 1, 2
for i := 2; i < n; i++ {
temp := n2
n2 = n1 + n2
n1 = temp
}

return n2
}

// [8,5,3,2,1,1]
Expand Down
2 changes: 1 addition & 1 deletion neetcode/0100-same-tree.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: trees, star1, easy, practice-count:2
// tags: trees, star1, easy, practice-count:3

/**
* Definition for a binary tree node.
Expand Down
2 changes: 1 addition & 1 deletion neetcode/0141-linked-list-cycle.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: linked-list, star3, todo(write), easy, practice-count:2
// tags: linked-list, star3, todo(write), easy, practice-count:3

/**
* Definition for singly-linked list.
Expand Down
2 changes: 1 addition & 1 deletion neetcode/0206-reverse-linked-list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: linked-list, star1, easy, practice-count:2
// tags: linked-list, star1, easy, practice-count:3

package neetcode

Expand Down
2 changes: 1 addition & 1 deletion neetcode/0208-implement-trie-prefix-tree.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: tries, medium, practice-count:2
// tags: tries, medium, practice-count:3

type Trie struct {
Child [26]*Trie
Expand Down
2 changes: 1 addition & 1 deletion neetcode/0322-coin-change.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: 1d-dp, star3, medium, practice-count:3
// tags: 1d-dp, star3, medium, practice-count:4

import "math"

Expand Down
2 changes: 1 addition & 1 deletion neetcode/0518-coin-change-ii.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: 2d-dp, star3, dfs, medium, practice-count:3
// tags: 2d-dp, star3, dfs, medium, practice-count:4

// time complexity: O(m*n)
// space complexity: O(m*n)
Expand Down
2 changes: 1 addition & 1 deletion neetcode/0704-binary-search.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tags: binary-search, star3, easy, practice-count:2
// tags: binary-search, star3, easy, practice-count:3

// time complexity: O(logn)
// space complexity: O(1)
Expand Down

0 comments on commit 90cb9a9

Please sign in to comment.