- 博客(30)
- 收藏
- 关注
原创 LeetCode - Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].http://oj.leetcode.
2014-01-30 06:00:44 489
原创 LeetCode - Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal 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},
2014-01-30 05:22:47 522
原创 LeetCode - Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gr
2014-01-30 04:56:28 508
原创 LeetCode - Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), d
2014-01-30 04:44:14 660
原创 LeetCode - Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using
2014-01-30 04:34:29 660
原创 LeetCode - Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ
2014-01-30 04:07:05 712
原创 LeetCode - Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.http://oj.leetcode.com/problems/integer-to-roman/Solution:First let's review the
2014-01-30 03:56:44 481
原创 LeetCode - Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]http://oj.leetcode.com/probl
2014-01-18 02:51:46 461
原创 LeetCode - Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You m
2014-01-18 02:18:07 456
原创 LeetCode - Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note: You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A
2014-01-16 03:51:43 522
原创 LeetCode - Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/Solution:Obvious
2014-01-16 03:46:01 512
原创 LeetCode - Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.http://oj.leetcode.com/problems/merge-two-sorted-lists/
2014-01-16 02:35:48 719
原创 LeetCode - Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.http://oj.leetcode.com/problems/roman-to-integer/Solution:First thing is to have
2014-01-16 02:08:24 441
原创 LeetCode - 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 followin
2014-01-16 01:51:39 435
原创 LeetCode - 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 t
2014-01-15 11:56:47 510
原创 LeetCode - Climbing Stairs
You are climbing a stair case. It takes n steps 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?http://oj.leetcode.com/problems/
2014-01-15 10:41:40 435
原创 LeetCode - Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.htt
2014-01-14 04:31:18 419
原创 LeetCode - Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with c
2014-01-14 04:03:21 433
原创 LeetCode - Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].http://oj.leetcode.com/problems
2014-01-14 03:12:42 486
原创 LeetCode - Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solution is tri
2014-01-14 01:23:09 600
原创 LeetCode - Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t
2014-01-14 00:46:00 578
原创 LeetCode - Search Insert Position
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. H
2014-01-13 15:49:01 906
原创 LeetCode - Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example, given 1->1->2, return 1->2; given 1->1->2->3->3, return 1->2->3.http://oj.leetcode.com/proble
2014-01-13 15:37:45 538
原创 LeetCode - Linked List Cycle
Given a linked list, determine if it has a cycle in it.http://oj.leetcode.com/problems/linked-list-cycle/Solution:Very popular problem. Use two pointer, p1 move two steps every time and p2
2014-01-13 15:31:34 428
原创 LeetCode - Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one
2014-01-13 15:27:10 498
原创 LeetCode - Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ /
2014-01-13 14:36:10 386
原创 LeetCode - Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321; x = -123, return -321http://oj.leetcode.com/problems/reverse-integer/Solution:Start from the last digit which is the input % 10, t
2014-01-13 14:02:07 424
原创 LeetCode - Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.http://oj.le
2014-01-13 13:46:00 493
原创 LeetCode - Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. http://oj.leetcode.com/problems/max
2014-01-13 13:40:49 440
原创 LeetCode - Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e
2014-01-13 13:33:57 487
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人