LeetCode解题
文章平均质量分 52
啊黎
渣渣研究生
展开
-
[LeetCode] 95. Unique Binary Search Trees II & I
[LeetCode] 95. Unique Binary Search Trees II & IGiven an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should ret原创 2017-02-27 00:10:05 · 184 阅读 · 0 评论 -
[LeetCode] 81. Search in Rotated Sorted Array II
[LeetCode] 81. Search in Rotated Sorted Array II Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why?Suppos原创 2017-02-25 01:31:34 · 151 阅读 · 0 评论 -
83 & 84. Remove Duplicates from Sorted List I & II
[LeetCode] 83 & 84. Remove Duplicates from Sorted List I & IIGiven 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原创 2017-02-25 01:38:54 · 147 阅读 · 0 评论 -
[LeetCode] 84. Largest Rectangle in Histogram
[LeetCode] 84. Largest Rectangle in HistogramGiven n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.原创 2017-02-25 01:41:12 · 293 阅读 · 0 评论 -
[LeetCode] 85. Maximal Rectangle
[LeetCode] 85. Maximal RectangleGiven a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.For example, given the following matrix: 1 0 1 0 0原创 2017-02-25 02:13:46 · 189 阅读 · 0 评论 -
[LeetCode] 86. Partition List
[LeetCode] 86. Partition ListGiven 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 should preserve the original relative order原创 2017-02-26 00:23:31 · 196 阅读 · 0 评论 -
[LeetCode] 87. Scramble String
[LeetCode] 87. Scramble StringGiven a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = “great”:原创 2017-02-26 00:28:53 · 205 阅读 · 0 评论 -
[LeetCode] 88. Merge Sorted Array
[LeetCode] 88. Merge Sorted ArrayGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or e原创 2017-02-26 00:37:31 · 185 阅读 · 0 评论 -
[LeetCode] 89. Gray Code
[LeetCode] 89. Gray CodeThe 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, pri原创 2017-02-26 00:47:27 · 179 阅读 · 0 评论 -
[LeetCode] 90. Subsets II
[LeetCode] 90. Subsets IIGiven a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example, If nums原创 2017-02-26 00:50:11 · 165 阅读 · 0 评论 -
[LeetCode] 91. Decode Ways
[LeetCode] 91. Decode WaysA message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26Given an encoded message containing dig原创 2017-02-26 23:46:48 · 183 阅读 · 0 评论 -
[LeetCode] 92. Reverse Linked List II
[LeetCode] 92. Reverse Linked List IIReverse 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:原创 2017-02-26 23:55:59 · 166 阅读 · 0 评论 -
[LeetCode] 93. Restore IP Addresses
[LeetCode] 93. Restore IP AddressesGiven a string containing only digits, restore it by returning all possible valid IP address combinations.For example: Given “25525511135”,return [“255.255.11.135”,原创 2017-02-27 00:01:17 · 174 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
[LeetCode] 94. Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 retur原创 2017-02-27 00:04:59 · 193 阅读 · 0 评论 -
[算法作业][LeetCode] 133. Clone Graph
[算法作业][LeetCode] 133. Clone GraphClone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization: Nodes are labeled uniquely.We use #原创 2017-03-19 23:07:33 · 216 阅读 · 0 评论 -
[LeetCode] 97. Interleaving String
[LeetCode] 97. 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. Wh原创 2017-02-27 23:47:54 · 309 阅读 · 0 评论 -
[LeetCode] 115. Distinct Subsequences
[LeetCode] 115. Distinct SubsequencesGiven 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 str原创 2017-03-03 13:45:10 · 208 阅读 · 0 评论 -
[LeetCode] 99. Recover Binary Search Tree
[LeetCode] 99. Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.一棵二叉搜索树,有两个节点换过来了,需要找出这两个节点,换回来。我们发现,一棵完好的BST,原创 2017-03-03 13:34:37 · 179 阅读 · 0 评论 -
[LeetCode] 68. Text Justification
[LeetCode] 68. Text JustificationGiven an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words原创 2017-02-21 21:52:13 · 183 阅读 · 0 评论 -
[LeetCode] 28. Implement strStr()
[LeetCode] 28. Implement strStr()Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.实现strStr(h, n)函数,如果在h中能找到n的完全匹配字符串,则返回对应的第一个原创 2017-02-21 23:16:52 · 219 阅读 · 0 评论 -
[LeetCode] 71. Simplify Path
[LeetCode] 71. Simplify PathGiven an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c”Corner Cases:Did you consider the ca原创 2017-02-22 01:00:08 · 145 阅读 · 0 评论 -
[LeetCode]69. Sqrt(x)
[LeetCode]69. Sqrt(x)Implement int sqrt(int x). Compute and return the square root of x.实现sqrt(x)函数。思想:二分查找m,使得m*m最接近x。注意m*m会超过int的范围。class Solution {public: int mySqrt(int x) { int l = 0原创 2017-02-21 21:49:18 · 206 阅读 · 0 评论 -
[LeetCode] 73. Set Matrix Zeroes
[LeetCode] 73. Set Matrix ZeroesGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up: Did you use extra space? A straight forward solution using O(mn原创 2017-02-23 01:31:52 · 210 阅读 · 0 评论 -
[LeetCode] 72. Edit Distance
[LeetCode] 72. Edit DistanceGiven 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 operatio原创 2017-02-23 01:18:12 · 185 阅读 · 0 评论 -
[LeetCode] 74. Search a 2D Matrix
[LeetCode] 74. Search a 2D MatrixWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.原创 2017-02-23 01:42:29 · 164 阅读 · 0 评论 -
[LeetCode] 75. Sort Colors
[LeetCode] 75. Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we w原创 2017-02-23 01:50:36 · 179 阅读 · 0 评论 -
[LeetCode] 76. Minimum Window Substring
[LeetCode] 76. Minimum Window SubstringGiven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example, S = “ADOBECODEBANC” T =原创 2017-02-23 22:01:27 · 255 阅读 · 0 评论 -
[LeetCode] 77. Combinations
[LeetCode] 77. CombinationsGiven two integers n and k, return all possible combinations of k numbers out of 1 … n.For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4],原创 2017-02-23 23:37:46 · 215 阅读 · 0 评论 -
[LeetCode] 78. Subsets
[LeetCode] 78. SubsetsGiven a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example, If nums = [1,2,3], a solution is: [原创 2017-02-23 23:41:06 · 181 阅读 · 0 评论 -
79. Word Search
[LeetCode] 79. Word SearchGiven 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 horiz原创 2017-02-23 23:53:21 · 160 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
[LeetCode] 80. Remove Duplicates from Sorted Array IIFollow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function原创 2017-02-23 23:59:25 · 166 阅读 · 0 评论 -
[LeetCode] 98. Validate Binary Search Tree
[LeetCode] 98. 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原创 2017-02-27 23:44:42 · 218 阅读 · 0 评论 -
[算法作业][LeetCode] 50. Pow(x, n) -- 分治法
[算法作业][LeetCode] 50. Pow(x, n) – 分治法Implement pow(x, n).对于xnx^n,可以通过分治的方法,设n=2kn = 2^k: xn=xn/2∗xn/2∗xn%2x^n = x^{n/2} * x^{n/2} * x^{n\%2} xn/2=xn/4∗xn/4∗xn/2%2x^{n/2} = x^{n/4} * x^{n/4} * x^{n/原创 2017-03-03 13:23:31 · 388 阅读 · 0 评论 -
[算法作业-动态规划][LeetCode] 97. Interleaving String
[算法作业-动态规划][LeetCode] 97. 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”, retur原创 2017-04-10 11:07:54 · 290 阅读 · 0 评论