Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Boolean can_reach_last_house(ArrayList<Integer> nums) {
- int [] table = new int[nums.size()];
- table[table.length-1] = 1; // last house is always 1
- for(int index = nums.size() -2; index>=0; index--) {
- for(int j = index + 1; j<= index + nums.get(index); j++){
- if(table[j] == 1) {
- table[index] = 1;
- break;
- }
- }
- }
- return table[0] == 1? true:false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement