-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #908 from 0xff-dev/330
Add solution and test-cases for problem 330
- Loading branch information
Showing
3 changed files
with
48 additions
and
25 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 |
---|---|---|
@@ -1,5 +1,19 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(nums []int, n int) int { | ||
patches := 0 | ||
maxReach := 0 | ||
i := 0 | ||
|
||
for maxReach < n { | ||
if i < len(nums) && nums[i] <= maxReach+1 { | ||
maxReach += nums[i] | ||
i++ | ||
} else { | ||
maxReach = 2*maxReach + 1 | ||
patches++ | ||
} | ||
} | ||
|
||
return patches | ||
} |
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