小白筆記-----------------------------leetcode53. Maximum Subarray

public class Solution {
    public int maxSubArray(int[] nums) {
        int count = 0;
        int max = nums[0];
        for(int i = 0;i < nums.length;i++){
            count = nums[i];
            if(count > max){
                    max = count;
            }
            for(int j = i+1;j < nums.length;j++){
                count +=  nums[j];
                if(count > max){
                    max = count;
                }
                
            }
             
        }
        return max;
    }
}


簡單的雙重遊標的思想就ok了
發佈了102 篇原創文章 · 獲贊 3 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章