摘要:
Generate ParenthesesGivennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"public class Solution { private ArrayLi 阅读全文
posted @ 2014-04-02 20:37
boole
阅读(118)
评论(0)
推荐(0)
摘要:
Plus OneGiven a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.public class Solution { public int[] plusOne(int[] digits) { int carry = 1; int temp; ... 阅读全文
posted @ 2014-04-02 20:14
boole
阅读(198)
评论(0)
推荐(0)
摘要:
Container With Most WaterGivennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains 阅读全文
posted @ 2014-04-02 19:55
boole
阅读(105)
评论(0)
推荐(0)
摘要:
Maximum SubarrayFind 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.public class Solution { public int maxSubArray(int[] A) { ... 阅读全文
posted @ 2014-04-01 22:14
boole
阅读(93)
评论(0)
推荐(0)
摘要:
Remove Duplicates from Sorted ListGiven 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./** * Definition for singly-linked list. * public class ListNode { * int val; * 阅读全文
posted @ 2014-04-01 22:01
boole
阅读(116)
评论(0)
推荐(0)
摘要:
Search Insert PositionGiven 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 阅读全文
posted @ 2014-04-01 22:00
boole
阅读(126)
评论(0)
推荐(0)
摘要:
Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.In... 阅读全文
posted @ 2014-04-01 21:59
boole
阅读(129)
评论(0)
推荐(0)
摘要:
Binary Tree Preorder TraversalGiven a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3]./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * ... 阅读全文
posted @ 2014-04-01 21:58
boole
阅读(114)
评论(0)
推荐(0)
摘要:
Binary Tree Inorder TraversalGiven a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2]./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * Tr... 阅读全文
posted @ 2014-04-01 21:54
boole
阅读(74)
评论(0)
推荐(0)
摘要:
Linked List CycleGiven a linked list, determine if it has a cycle in it./** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public boolean hasCycle... 阅读全文
posted @ 2014-04-01 21:50
boole
阅读(89)
评论(0)
推荐(0)