File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 26
26
- [ 3 Sum] ( #3-sum )
27
27
- [ 3 Sum Closest] ( #3-sum-closest )
28
28
- [ Letter combinations of a phone number] ( #letter-combinations-of-a-phone-number )
29
+ - [ Jump Game II] ( #jump-game-ii )
29
30
30
31
### String to Int - Atoi
31
32
@@ -719,4 +720,26 @@ void lookupChar(
719
720
}
720
721
}
721
722
}
723
+ ```
724
+
725
+ ### Jump Game II
726
+
727
+ ``` dart
728
+ int jump(List<int> nums) {
729
+ if (nums.isEmpty) return 0;
730
+
731
+ int result = 0;
732
+ int maxNumber = 0;
733
+ int cur = 0;
734
+
735
+ for (var i = 0; i < nums.length - 1; i++) {
736
+ maxNumber = max(maxNumber, i + nums[i]);
737
+ if (i == cur) {
738
+ result++;
739
+ cur = maxNumber;
740
+ }
741
+ }
742
+
743
+ return result;
744
+ }
722
745
```
Original file line number Diff line number Diff line change
1
+ import 'dart:math' ;
2
+
3
+ void main (List <String > args) {
4
+ List <List <int >> cases = [
5
+ [2 , 3 , 1 , 1 , 4 ],
6
+ [2 , 3 , 0 , 1 , 4 ]
7
+ ];
8
+
9
+ for (final testcase in cases) {
10
+ print (jump (testcase));
11
+ }
12
+ }
13
+
14
+ int jump (List <int > nums) {
15
+ if (nums.isEmpty) return 0 ;
16
+
17
+ int result = 0 ;
18
+ int maxNumber = 0 ;
19
+ int cur = 0 ;
20
+
21
+ for (var i = 0 ; i < nums.length - 1 ; i++ ) {
22
+ maxNumber = max (maxNumber, i + nums[i]);
23
+ if (i == cur) {
24
+ result++ ;
25
+ cur = maxNumber;
26
+ }
27
+ }
28
+
29
+ return result;
30
+ }
You can’t perform that action at this time.
0 commit comments