File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -166,3 +166,9 @@ so that you can use `just tf TEST` command to test.
166166|  Problem |  Difficulty |  Solution | 
167167|  - |  - |  - | 
168168|  56. Merge Intervals |  Medium |  [ 56_merge_intervals.rs] ( ./tests/56_merge_intervals.rs )  | 
169+ 
170+ ### Greedy  
171+ 
172+ |  Problem |  Difficulty |  Solution | 
173+ |  - |  - |  - | 
174+ |  55. Jump Game |  Medium |  [ 55_jump_game.rs] ( ./tests/55_jump_game.rs )  | 
Original file line number Diff line number Diff line change 1+ // 55. Jump Game 
2+ // https://leetcode.com/problems/jump-game/description/ 
3+ // Topics: Greedy. 
4+ // Difficulty: Medium. 
5+ 
6+ #[ test]  
7+ fn  test_55_jump_game ( )  { } 
8+ 
9+ #[ derive( Debug ) ]  
10+ pub  struct  Solution ; 
11+ 
12+ // --------------------------------- 
13+ // copy to leetcode starts from here 
14+ // --------------------------------- 
15+ 
16+ impl  Solution  { 
17+     pub  fn  can_jump ( nums :  Vec < i32 > )  -> bool  { 
18+         let  mut  max_reach:  usize  = 0 ; 
19+         for  ( i,  & item)  in  nums. iter ( ) . enumerate ( )  { 
20+             if  i > max_reach { 
21+                 return  false ; 
22+             } 
23+             max_reach = max_reach. max ( i + item as  usize ) ; 
24+             if  max_reach >= nums. len ( )  - 1  { 
25+                 return  true ; 
26+             } 
27+         } 
28+         false 
29+     } 
30+ } 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments