- 博客(27)
- 资源 (4)
- 收藏
- 关注
原创 [LeetCode] Validate binary search tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The
2013-03-23 03:11:37 1092
原创 [LeetCode]Remove N-th node from end of list
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, t
2013-03-22 10:50:25 612
原创 [LeetCode] Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".class Solution {public: string addBinary(string a, string b) { // S
2013-03-19 12:02:02 598
原创 [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?1. direct solution:with recu
2013-03-19 11:37:36 873
原创 [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 o
2013-03-19 11:21:01 684
原创 [LeetCode] Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a w
2013-03-18 10:49:40 491
原创 [LeetCode]Unique Paths I & II
I. A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach
2013-03-17 08:41:59 1480
原创 [leetCode] Plus One
Given a number represented as an array of digits, plus one to the number.class Solution {public: vector plusOne(vector &digits) { // Start typing your C/C++ solution below
2013-03-16 10:36:44 545
原创 [LeetCode] Binary tree level order traversal I & II
1. Given a binary tree, return the level order traversal 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
2013-03-15 09:02:48 520
原创 [LeetCode] Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [
2013-03-14 23:40:47 557
原创 [LeetCode] Best Time to Buy and Sell Stock III
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 at most two transactions.Note:You
2013-03-14 08:35:09 2780
原创 [LeetCode] Best time to buy and sell a 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
2013-03-14 03:19:48 670
原创 [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
2013-03-14 03:04:41 744
原创 [leetcode] populating next right pointer in a binary tree
1. perfect binary treeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to poi
2013-03-12 09:25:47 629
原创 Pascal's Triangle I & II
1. 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]]class Solution {pu
2013-03-06 11:22:20 556
原创 [LeetCode] Sum root to leaf numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the to
2013-03-05 09:04:02 1951
原创 [LeetCode] Interleave String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc",
2013-03-05 06:56:09 2036
原创 [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 f
2013-03-05 03:12:34 666
原创 [LeetCode] Flatten Tree into Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1
2013-03-05 00:29:18 640
原创 [LeetCode] Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array ret
2013-03-04 23:49:54 377
原创 [leetcode] Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Can u do this in place?思路:从外圈四边开始转,总是(i,j)--> (j,n-1-i)。递归到内圈class Solut
2013-03-04 23:22:54 837
原创 [leetcode] Same Tree
1. In-order Traverse and print tree. Compare the printed strings.class Solution {public: bool isSameTree(TreeNode *p, TreeNode *q) { // Start typing your C/C++ solution below //
2013-03-04 11:25:23 356
原创 [leetcode] sqrt(int num)
Implement int sqrt(int x).Compute and return the square root of x.TestCases:inputoutputexpected 000 111 211 311 422 522 622 722 822 933 1033 10243232 81929090 214739559946
2013-03-03 05:13:37 1571
原创 [Leetcode] World Ladder
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exist i
2013-03-03 01:43:23 749
原创 [leetcode] Reverse a linked list
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy
2013-03-01 23:41:29 435
原创 vector使用
FROM LEETCODE: Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.
2013-03-01 10:22:56 586
原创 Binary Tree Maximum Path Sum[leet code test cases passed]
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3answer: 6 (can be a
2013-03-01 08:48:00 1188
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人