摘要: Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return[1,2,3,6,9,8,7,4,5].class Solution {public: vector spiralOrder(vector > &matrix) { vector ans; ... 阅读全文
posted @ 2013-12-15 14:03 七年之后 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray[4,−1,2,1]has the largest sum =6.思考:最大字串和。class Solution {public: int maxSubArray(int A[], int n) { int last=A[... 阅读全文
posted @ 2013-12-15 00:13 七年之后 阅读(179) 评论(0) 推荐(0) 编辑