LeetCode
文章平均质量分 74
honze
这个作者很懒,什么都没留下…
展开
-
[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 (size that is greater or equal to m + n) to hold additional elements from原创 2014-09-17 16:28:38 · 128 阅读 · 0 评论 -
[LeetCode]Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.原创 2014-09-03 19:48:44 · 95 阅读 · 0 评论 -
[LeetCode]Subset I/II
Given 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 duplicate subsets.For exa原创 2014-09-16 10:19:11 · 198 阅读 · 0 评论 -
[LeetCode]Sort List
Sort a linked list in O(n log n) time using constant space complexity.原创 2014-09-03 20:33:34 · 132 阅读 · 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 non原创 2014-09-01 23:47:14 · 118 阅读 · 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; * List原创 2014-08-17 16:06:00 · 106 阅读 · 0 评论 -
[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. Y原创 2014-08-17 15:31:13 · 100 阅读 · 0 评论 -
[LeetCode]Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2014-08-17 22:26:33 · 152 阅读 · 0 评论 -
[LeetCode]Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-08-17 21:52:55 · 111 阅读 · 0 评论 -
[LeetCode]Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2014-08-17 15:06:57 · 126 阅读 · 0 评论 -
[LeetCode]Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without an原创 2014-08-15 13:27:06 · 103 阅读 · 0 评论 -
[LeetCode]Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-08-29 22:29:28 · 83 阅读 · 0 评论 -
[LeetCode]Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2014-08-29 22:57:57 · 105 阅读 · 0 评论 -
[LeetCode]ZigZag Conversion
The 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 legibility)P A H NA P L S I原创 2014-08-29 17:04:06 · 110 阅读 · 0 评论 -
[LeetCode]Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.根据原创 2014-08-29 17:32:45 · 102 阅读 · 0 评论 -
[LeetCode]Insertion Sort List
Sort a linked list using insertion sort.原创 2014-09-03 22:48:49 · 87 阅读 · 0 评论 -
[LeetCode]Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t原创 2014-09-03 15:33:48 · 126 阅读 · 0 评论 -
[LeetCode]GrayCode
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原创 2014-09-17 16:17:33 · 184 阅读 · 0 评论 -
[LeetCode]Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?设经过x原创 2014-09-05 00:26:01 · 111 阅读 · 0 评论 -
[LeetCode]Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary原创 2014-09-04 21:16:55 · 103 阅读 · 0 评论 -
[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].Note: Recursive soluti原创 2014-09-04 14:24:59 · 105 阅读 · 0 评论 -
[LeetCode]Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?原创 2014-09-04 23:37:53 · 103 阅读 · 0 评论 -
[LeetCode]Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to原创 2014-09-04 23:24:52 · 102 阅读 · 0 评论 -
[LeetCode]Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.原创 2014-09-04 20:53:59 · 176 阅读 · 0 评论 -
[LeetCode]Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.设f(n)表示以n为根节点的二叉树到原创 2014-09-04 20:01:11 · 101 阅读 · 0 评论 -
[LeetCode]Binary Tree Maximum Path Sum
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 3Return 6.原创 2014-09-04 17:37:03 · 118 阅读 · 0 评论 -
[LeetCode]Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.原创 2014-09-25 14:54:47 · 185 阅读 · 0 评论 -
[LeetCode]Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut原创 2014-09-04 00:00:40 · 96 阅读 · 0 评论 -
[LeetCode]LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2014-09-03 23:26:28 · 102 阅读 · 0 评论 -
[LeetCode]Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",原创 2014-09-03 17:27:31 · 116 阅读 · 0 评论 -
[LeetCode]Reverse Words in a String
class Solution {public: void reverse(string &s, int i, int j) { while (i < j) swap(s[i++], s[j--]); } void reverseWords(string &s) { // 调整s使得以单个空格原创 2014-09-03 16:35:08 · 106 阅读 · 0 评论 -
[LeetCode]String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2014-08-28 23:31:51 · 454 阅读 · 0 评论 -
[LeetCode]Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st原创 2014-08-28 22:00:54 · 101 阅读 · 0 评论 -
[LeetCode]Longest Valid Parentheses
Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid原创 2014-08-14 17:05:36 · 114 阅读 · 0 评论 -
[LeetCode]Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "原创 2014-09-05 19:17:52 · 121 阅读 · 0 评论 -
[LeetCode]Word Break
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 words.For example, givens = "leetcode",dict = ["leet"原创 2014-09-05 17:26:44 · 104 阅读 · 0 评论 -
[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.原创 2014-08-21 11:34:55 · 112 阅读 · 0 评论 -
[LeetCode]Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list. 写了几遍都是rum原创 2014-09-05 23:50:16 · 112 阅读 · 0 评论 -
[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.根本不知道罗马数字怎么原创 2014-08-21 10:09:46 · 161 阅读 · 0 评论 -
[LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.原创 2014-09-04 20:47:04 · 124 阅读 · 0 评论