找LeetCode上简单的题目来撑过30天啦(DAY16)

ok,今天挑战同一张证照第三次失败了,有够难过的,但至少分述有越来越接近啦,再接再厉罗

题号:55 标题:Jump Game 难度:Medium

You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return true if you can reach the last index, or false otherwise.

Example 1:
Input: nums = [2,3,1,1,4]
Output: true
Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.

Example 2:
Input: nums = [3,2,1,0,4]
Output: false
Explanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.

Constraints:
• 1 <= nums.length <= 104
• 0 <= nums[i] <= 105

class Solution {
    public boolean canJump(int[] nums) {
        int i=0,j=0,k=0;
        int[] temp = new int[nums.length+1];
        ArrayList<Integer> arrlist = new ArrayList<Integer>();
        
        for(i=0;i<nums.length;i++){
            arrlist.add(nums[i]);
        }
        if(!arrlist.contains(0)){
            return true;
        }
        
        if(nums[0]==0){
            if(nums.length==1){
                return true;
            }else{
                return false;
            }
        }
        int count0=0,chk0=0;
        for(i=nums.length-1;i>=0;i--){
            if(nums[i]==0){
                count0++;
                chk0=1;
               
            }else if(chk0==1 && nums[i]!=0 ){
                k=0;
                for(j=i;j>=0;j--){
                    if(nums[j]>(count0+k)){
                        chk0=0;
                        count0=0;
                        break;
                    }else if(count0+i+1==nums.length && nums[j]==(count0+k)){
                        chk0=0;
                        count0=0;
                        break;
                    }else if(j==0){
                        return false;
                    }
                    k++;
                }
            }
        }
        
        return true;
    }
}

DAY16心得
证照跟铁人赛还有上班三头烧,我已经再用测资测试程序了,看看我把CASE一个个判断出来
1.没有0的一定到的了=>TRUE
2.第一个值为0,一定到不了=>FALSE
3.接下来就是判断连续几个0前面的值要能够跨过去,能够跨过去就继续搜寻有没有0,跨不过去就代表到不了=>FALSE


<<:  MyBatis 前导

>>:  [Day29] 倒数第二天~集大成!Next.js + React + Bootstrap + Reactstrap 十八般武艺(?)样样来,勇敢的上吧!

Day 22 - Rancher Fleet 架构介绍

本文将於赛後同步刊登於笔者部落格 有兴趣学习更多 Kubernetes/DevOps/Linux 相...

[Day27] VSCode Plugin - WakaTime

官网连结 VSCode Marketplace 推荐程度:⭐⭐⭐⭐⭐ 有在写工作日志或周志,或是想...

万事起头难

我对VR的第一印象,就是一个人戴着罩住眼睛的头盔,手拿着摇杆的游戏。但是这个软件到底要怎麽制作,且是...

[第24天]理财达人Mx. Ada-RSI指标

前言 本文说明RSI指标。 RSI指标 RSI(Relative Strength Index):相...

Day17 requests模组二

今天的影片内容为解释向网页服务器请求资料失败可能的原因 以及碰到「反爬虫机制」的应对方法 以下为影片...