Skip to content

Commit 9f5bb31

Browse files
committed
leetcode : jump problem
1 parent d53776c commit 9f5bb31

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

problem57/main.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
import 'dart:math';
3+
4+
void main(List<String> args) {
5+
print(canJump([3,2,1,0,4]));
6+
}
7+
8+
9+
bool canJump(List<int> nums) {
10+
int reach=0;
11+
for(int i=0;i<nums.length;i++){
12+
if(reach<i){
13+
return false;
14+
}
15+
if(reach==nums.length-1){
16+
return true;
17+
}
18+
reach=max(reach, i+nums[i]);
19+
}
20+
return true;
21+
}

0 commit comments

Comments
 (0)