2013年9月11日

[leetcode.com]算法题目 - Maximum Subarray

摘要: 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. 1 class Solution { 2 public: 3 int maxSubArray(int A[], int n) { 4 // Start... 阅读全文

posted @ 2013-09-11 22:27 Horstxu 阅读(201) 评论(0) 推荐(0) 编辑

[leetcode.com]算法题目 - Plus One

摘要: Given a number represented as an array of digits, plus one to the number. 1 class Solution { 2 public: 3 vector plusOne(vector &digits) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 bool allNine = true; 7 int size = digi... 阅读全文

posted @ 2013-09-11 22:18 Horstxu 阅读(241) 评论(0) 推荐(0) 编辑

[leetcode.com]算法题目 - Remove Duplicates from Sorted List

摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode 阅读全文

posted @ 2013-09-11 21:53 Horstxu 阅读(260) 评论(0) 推荐(0) 编辑

[leetcode.com]算法题目 - Symmetric Tree

摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iterati... 阅读全文

posted @ 2013-09-11 20:37 Horstxu 阅读(189) 评论(0) 推荐(0) 编辑

导航