LeetCode
文章平均质量分 64
iteye_8091
这个作者很懒,什么都没留下…
展开
-
[LeetCode] Validate Binary Search Tree
Validate Binary Search TreeGiven 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 ...2013-04-28 22:50:27 · 108 阅读 · 0 评论 -
[Leetcode] Binary Tree Level Order Traversal
Binary Tree Level Order TraversalSep 29 '125832 / 14746Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given b...2013-09-10 14:39:15 · 91 阅读 · 0 评论 -
[Leetcode] Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search TreeOct 3 '125768 / 16298Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. /** * Defi...2013-09-11 16:06:34 · 87 阅读 · 0 评论 -
[Leetcode] Decode Ways
Decode WaysJun 25 '126747 / 26583A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded ...2013-09-11 17:33:06 · 65 阅读 · 0 评论 -
[Leetcode] Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or v...2013-09-21 23:21:41 · 78 阅读 · 0 评论 -
[Leetcode] Partition List
Partition List AC Rate: 428/1694My Submissions Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You s...原创 2013-09-29 23:38:02 · 77 阅读 · 0 评论 -
[Leetcode] Scramble String
Scramble String AC Rate: 318/1523My Submissions Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one p...2013-10-03 16:55:11 · 78 阅读 · 0 评论 -
[Leetcode] Remove Duplicates from Sorted List 1 & 2
Remove Duplicates from Sorted List AC Rate: 984/2755My Submissions Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1-...2013-10-03 23:34:35 · 106 阅读 · 0 评论 -
[Leetcode] Path Sum
Path Sum AC Rate: 872/2770My Submissions Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals t...原创 2013-10-03 23:52:53 · 103 阅读 · 0 评论 -
[Leetcode] Subsets 1 ^& 2
SubsetsApr 18 '126226 / 16269Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain...2013-09-09 21:42:58 · 68 阅读 · 0 评论 -
[Leetcode] Unique Paths II
Unique Paths IIMar 29 '124573 / 11497Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is ...2013-09-09 21:10:42 · 81 阅读 · 0 评论 -
[Leetcode] Multiply Strings
Multiply StringsMar 12 '124253 / 16074Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negativ...2013-08-20 18:48:44 · 83 阅读 · 0 评论 -
[Leetcode] Wildcard Matching
Wildcard MatchingMar 16 '127489 / 29783Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the...2013-08-22 10:07:47 · 85 阅读 · 0 评论 -
[Leetcode] Jump Game / Jump Game II
Jump GameMar 25 '126923 / 16241Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump len...2013-08-22 10:31:25 · 85 阅读 · 0 评论 -
[Leetcode] Permutations / Permutations II
Permutations IIMar 17 '124943 / 12877Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permuta...2013-08-22 15:41:54 · 88 阅读 · 0 评论 -
[Leetcode] Rotate Image
Rotate ImageMar 18 '124182 / 9471You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place? 这题我第一次做时候,实现的非...2013-08-22 15:54:25 · 74 阅读 · 0 评论 -
[Leetcode] Balanced Binary Tree
Balanced Binary TreeOct 9 '127722 / 18479Given 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...2013-08-27 20:53:01 · 99 阅读 · 0 评论 -
[Leetcode] Triangle
TriangleOct 30 '126503 / 17796Given 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 tria...2013-09-04 16:32:45 · 88 阅读 · 0 评论 -
[Leetcode] Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked ListOct 14 '127105 / 21371Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ ...2013-09-09 02:35:44 · 85 阅读 · 0 评论 -
[Leetcode] Copy List with Random Pointer
Copy List with Random Pointer AC Rate: 350/1573My Submissions A linked list is given such that each node contains an additional random pointer which could point to any node in the ...2013-10-05 22:43:13 · 92 阅读 · 0 评论 -
[Leetcode] Single Number 1 & 2
Single Number AC Rate: 1243/2713My Submissions Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a ...2013-10-05 22:50:54 · 121 阅读 · 0 评论 -
[LeetCode] Interleaving String
Interleaving StringGiven 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 = "a...2013-01-03 18:26:32 · 62 阅读 · 0 评论 -
[LeetCode] ZigZag Conversion
ZigZag ConversionDec 6 '11The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legib...2013-03-01 23:52:25 · 86 阅读 · 0 评论 -
[LeetCode] Word Ladder
Word LadderGiven two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach i...2013-03-05 00:43:56 · 77 阅读 · 0 评论 -
[LeetCode] Longest Consecutive Sequence
Longest Consecutive SequenceFeb 14Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest conse...2013-03-05 14:51:06 · 93 阅读 · 0 评论 -
[LeetCode] Surrounded Regions
Surrounded RegionsFeb 22Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For ex...2013-03-05 17:36:14 · 78 阅读 · 0 评论 -
[LeetCode] Triangle
TriangleOct 30 '12Given 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[ ...2013-03-13 23:36:16 · 76 阅读 · 0 评论 -
[LeetCode] Populating Next Right Pointers in Each Node II
Populating Next Right Pointers in Each Node IIOct 28 '12423 / 1042Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would yo...2013-04-09 14:56:02 · 80 阅读 · 0 评论 -
[LeetCode] Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis...2013-04-23 00:01:50 · 63 阅读 · 0 评论 -
[LeetCode] Insert Interval
Insert IntervalGiven a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to the...2012-12-16 23:54:05 · 74 阅读 · 0 评论 -
[LeetCode] Implement strStr()
Implement strStr()Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.方法:KMP正好趁这个题目温习了一下KMP字符串匹配。母串S, 模式串PKMP算法...2012-12-15 14:17:17 · 109 阅读 · 0 评论 -
[Leetcode] Word Break 1 & 2
Word Break AC Rate: 2/13My Submissions Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary w...2013-10-05 23:26:18 · 157 阅读 · 0 评论 -
[Leetcode] Gas Station
Gas Station AC Rate: 1017/4717My Submissions There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas ...2013-10-07 00:02:52 · 182 阅读 · 0 评论 -
[LeetCode]Best Time to Buy and Sell Stock 1 2 3
1. 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 ...原创 2012-11-15 22:14:28 · 80 阅读 · 0 评论 -
[LeetCode]Binary Tree Traversal & Binary Tree Maximum Path Sum
本文LeetCode(http://www.leetcode.com/onlinejudge)内的binary tree travel,包含3个:1). Binary Tree Inorder Traversal2). Binary Tree Level Order Traversal3). Binary Tree Maximum Path Sum 1). Binary Tr...原创 2012-11-16 22:33:51 · 119 阅读 · 0 评论 -
[LeetCode]Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find t...原创 2012-11-26 20:26:09 · 66 阅读 · 0 评论 -
[LeetCode]Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be no...2012-12-11 22:37:06 · 77 阅读 · 0 评论 -
[LeetCode]Divide Two Integers
Divide Two IntegersDivide two integers without using multiplication, division and mod operator.不用*, /, %来实现除法。注意:1.正负号;2.INT_min=-2147483648,变为正数越界。const int INTMIN = -2147483648;c...2012-12-13 00:20:08 · 66 阅读 · 0 评论 -
[LeetCode]First Missing Positive
First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) t...2012-12-13 01:16:29 · 73 阅读 · 0 评论 -
[Leetcode] Trapping Rain Water
Trapping Rain WaterMar 10 '124164 / 10550Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining....2013-08-20 13:10:57 · 67 阅读 · 0 评论