剑指offer题答案笔记
1.二维数组中的查找/*思路:二维数组从上到下,从左到右递增的规律选取右上角的元素与target比较target a[row][col],target在元素所在列的下边 row++target==a[row][col] 返回true当row > array[0].length -1 || col <0 没有找到*/public class Solution { public boolean Find(int target, int [][] array) { int row = 0;//行 int col = array[0].length -1;//列 while(row <= array[0].length -1 && col >=0){ if(target == array[row][col]) return true; else if(target < array[row][col]) col--; else row++; } return false; }}
1.连续子数组的最大和
动态规划class Solution {public: int FindGreatestSumOfSubArray(vector array) { int size = array.size(); if(size == 0) return 0; int maxSum = array[0]; int sum = 0; for(int i= 0;imaxSum){ maxSum =sum; } } return maxSum; }};