3028. Ant on the Boundary

题目 3028. Ant on the Boundary

image-e3b5afb4

思路分析

image-3ed2d410

代码实现

class Solution {
    public int returnToBoundaryCount(int[] nums) {
        int cur=0,cnt=0;
        for(int i=0;i<nums.length;i++){
            cur+=nums[i];
            if(cur==0){
                cnt++;
            }
        }
        return cnt;
    }
}

同类题型

视频讲解