邓心一 6 anos atrás
pai
commit
1e6be4777c
4 arquivos alterados com 77 adições e 3 exclusões
  1. 3 3
      hard/44.go
  2. 46 0
      hard/45.go
  3. 22 0
      hard/57.go
  4. 6 0
      hard/helper.go

+ 3 - 3
hard/44.go

@@ -4,6 +4,6 @@ func isMatch(s string, p string) (ans bool) {
 	return
 }
 
-func main() {
-
-}
+// func main() {
+// 	// Is it the same with no. 10??
+// }

+ 46 - 0
hard/45.go

@@ -0,0 +1,46 @@
+package main
+
+func jumpSlow(nums []int) (steps int) { // TLE?
+	n := len(nums)
+	if n == 0 {
+		return
+	}
+	dist := make([]int, n)
+	for i := range nums {
+		for j := 1; j <= nums[i] && i+j < n; j++ {
+			if dist[i+j] == 0 || dist[i] < dist[i+j] {
+				dist[i+j] = dist[i] + 1
+			}
+		}
+	}
+	return dist[n-1]
+}
+
+func jump(nums []int) (steps int) {
+	n := len(nums)
+	if n <= 1 {
+		return
+	}
+	stop, nextStop := nums[0], nums[0]
+	for i := range nums {
+		if nextStop < i+nums[i] {
+			nextStop = i + nums[i]
+		}
+		if i == stop || i == n-1 {
+			stop = nextStop
+			steps++
+		}
+	}
+	return
+}
+
+// func main() {
+// 	n := []int{2, 3, 1, 1, 4}
+// 	println(jump(n))
+// 	n = []int{}
+// 	println(jump(n))
+// 	n = []int{2, 1}
+// 	println(jump(n))
+// 	n = []int{0}
+// 	println(jump(n))
+// }

+ 22 - 0
hard/57.go

@@ -0,0 +1,22 @@
+package main
+
+import (
+	"fmt"
+)
+
+/**
+ * Definition for an interval.
+ * type Interval struct {
+ *	   Start int
+ *	   End   int
+ * }
+ */
+func insert(intervals []Interval, newInterval Interval) (in []Interval) {
+	return
+}
+
+func main() {
+	in := []Interval{{1, 2}, {3, 5}, {6, 7}, {8, 10}, {12, 16}}
+	ans := insert(in, Interval{1, 2})
+	fmt.Println(ans)
+}

+ 6 - 0
hard/helper.go

@@ -17,6 +17,12 @@ type TreeNode struct {
 	Right *TreeNode
 }
 
+// Interval ...
+type Interval struct {
+	Start int
+	End   int
+}
+
 func abs(x int) int {
 	if x < 0 {
 		return -x