首页 > 其他分享 >只有代码,妹有记录 【速速补充】

只有代码,妹有记录 【速速补充】

时间:2022-11-20 22:24:13浏览次数:40  
标签:妹有 速速 right end nums int 代码 answer left

【速速补充笔记】

977.有序数组的平方

class Solution {
    public int[] sortedSquares(int[] nums) {
        int left = 0, right = nums.length - 1, point = right;
        int[] answer = new int[nums.length];
        while (left <= right) {
            if ((nums[right] * nums[right]) > (nums[left] * nums[left])) {
                answer[point] = nums[right] * nums[right];
                right--;
            } else {
                answer[point] = nums[left] * nums[left];
                left++;
            }
            point--;
        }
        return answer;
    }
}

209.长度最小的子数组

class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int end, start = 0;
        int sum = 0;
        int answer = nums.length + 1;
        int subLength;
        for (end = 0; end < nums.length; end++) {
            sum += nums[end];
            while (sum >= target) {
                subLength = end - start + 1;
                answer = Math.min(answer, subLength);
                sum -= nums[start];
                start++;
            }
        }
        return answer == nums.length + 1 ? 0 : answer;

    }
}

标签:妹有,速速,right,end,nums,int,代码,answer,left
From: https://www.cnblogs.com/Chain-Tian/p/16909804.html

相关文章