forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Golang solution for lcof problem 10-11
- Loading branch information
1 parent
ec51232
commit c09abd7
Showing
6 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
func fib(n int) int { | ||
if n < 2 { | ||
return n | ||
} | ||
a := make([]int,n+1) | ||
a[0]=0 | ||
a[1]=1 | ||
for i := 2; i < n+1; i++ { | ||
a[i] = (a[i-1]+ a[i-2])%1000000007 | ||
} | ||
return a[n] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
func numWays(n int) int { | ||
if n == 0 { | ||
return 1 | ||
} | ||
if n <= 2 { | ||
return n | ||
} | ||
a := make([]int,n) | ||
a[0] = 1 | ||
a[1] = 2 | ||
for i := 2; i<n; i++ { | ||
a[i] = (a[i-1]+a[i-2])%1000000007 | ||
} | ||
return a[n-1] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
func minArray(nums []int) int { | ||
l,r := 0,len(nums)-1 | ||
for l < r { | ||
mid := l + (r-l)>>1 | ||
if nums[mid] > nums[r] { | ||
l = mid + 1 | ||
} else if nums[mid] <nums[r] { | ||
r = mid //r 本身不需要被排除 | ||
} else { | ||
r-- | ||
} | ||
} | ||
return nums[l] | ||
} |