摘要: 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.More practice:If you have figured out the O(n) solution, try coding another solution usi 阅读全文
posted @ 2013-10-15 11:36 昱铭 阅读(167) 评论(0) 推荐(0)
摘要: You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?==============================================================Fisrt, I tried recursive way.1 class Solution {2 public:3 int climbStair... 阅读全文
posted @ 2013-10-14 17:03 昱铭 阅读(305) 评论(0) 推荐(0)
摘要: 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.==========================================================Nothing, patience, AC once. 1 /** 2 * Definition for si 阅读全文
posted @ 2013-10-14 16:37 昱铭 阅读(148) 评论(0) 推荐(0)
摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?========================================================================Remember this property of 阅读全文
posted @ 2013-10-13 11:50 昱铭 阅读(151) 评论(0) 推荐(0)
摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2013-10-11 15:56 昱铭 阅读(190) 评论(0) 推荐(0)
摘要: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]====... 阅读全文
posted @ 2013-09-27 17:36 昱铭 阅读(124) 评论(0) 推荐(0)
摘要: Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its level order traversal as:[ [3], [9,20], [15,7]]confused what"{1,#,2,3}"means?OJ's Binary 阅读全文
posted @ 2013-09-27 17:17 昱铭 阅读(168) 评论(0) 推荐(0)
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0================== 阅读全文
posted @ 2013-09-27 11:47 昱铭 阅读(177) 评论(0) 推荐(0)
摘要: Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?confused what"{1,#,2,3}"means?OJ's Binary Tree Serialization:The serialization of a bi 阅读全文
posted @ 2013-09-27 11:15 昱铭 阅读(165) 评论(0) 推荐(0)
摘要: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!If the integer's last digit is 0, what should the output be? ie, cas 阅读全文
posted @ 2013-09-27 10:07 昱铭 阅读(129) 评论(0) 推荐(0)