
LeetCode
narcssusinnook
这个作者很懒,什么都没留下…
展开
-
[LeetCode]Codes of Easy Problem
[LeetCode]Code of Easy Problem原创 2016-02-05 22:05:07 · 745 阅读 · 0 评论 -
[LeetCode]Missing Number
Problem Description[https://leetcode.com/problems/missing-number/] Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Give原创 2016-03-09 10:48:38 · 221 阅读 · 0 评论 -
[LeetCode]297. Serialize and Deserialize Binary Tree
Problem DescriptionSerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network con原创 2016-02-23 19:43:36 · 288 阅读 · 0 评论 -
[LeetCode]108. Convert Sorted Array to Binary Search Tree
Problem DescriptionGiven an array where elements are sorted in ascending order, convert it to a height balanced BST. [https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/]思路二分!!!就原创 2016-03-08 18:36:02 · 310 阅读 · 0 评论 -
[LeetCode]49. Group Anagrams
Problem DescriptionGiven an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ]原创 2016-03-08 18:05:02 · 270 阅读 · 0 评论 -
[LeetCode]73. Set Matrix Zeroes
Problem DescriptionGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. https://leetcode.com/problems/set-matrix-zeroes/思路如果要用O(1)的额外空间的话,利用数组第0列和第0行来记录0的位置就好了原创 2016-02-23 15:13:49 · 263 阅读 · 0 评论 -
[LeetCode]139. Word Break
Problem DescriptionGiven 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, given s = “leetcode”,原创 2016-03-08 16:10:34 · 222 阅读 · 0 评论 -
[LeetCode]331. Verify Preorder Serialization of a Binary Tree
Problem DescriptionOne way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node’s value. If it is a null node, we record using a sentinel valu原创 2016-03-07 15:34:22 · 374 阅读 · 0 评论 -
[LeetCode]96. Unique Binary Search Trees
Problem DescriptionGiven n, how many structurally unique BST’s (binary search trees) that store values 1…n? [https://leetcode.com/problems/unique-binary-search-trees/]思路DP!状态转移方程: DP[n]=DP[0]*DP[n-1原创 2016-03-07 14:48:42 · 238 阅读 · 0 评论 -
[LeetCode]330. Patching Array
Problem DescriptionGiven a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements原创 2016-03-07 14:24:45 · 494 阅读 · 0 评论 -
[LeetCode]198. House Robber
Problem DescriptionYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is t原创 2016-02-21 18:16:00 · 359 阅读 · 0 评论 -
[LeetCode]306. Additive Number
Problem DescriptionAdditive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent原创 2016-02-21 17:45:01 · 419 阅读 · 0 评论 -
[LeetCode]86. Partition List
Problem DescriptionGiven 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 of the no原创 2016-02-21 14:54:00 · 299 阅读 · 0 评论 -
[LeetCode]236. Lowest Common Ancestor of a Binary Tree
Problem DescriptionGiven a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2016-03-07 10:55:24 · 328 阅读 · 0 评论 -
[LeetCode]235. Lowest Common Ancestor of a Binary Search Tree
Problem DescriptionGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is原创 2016-03-07 10:51:21 · 289 阅读 · 0 评论 -
[LeetCode]233. Number of Digit One
Problem DescriptionGiven an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example: Given n = 13, Return 6, because digit 1 occurred i原创 2016-03-06 16:17:09 · 294 阅读 · 0 评论 -
[LeetCode]62. Unique Paths
Problem DescriptionA 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原创 2016-03-06 15:36:18 · 243 阅读 · 0 评论 -
[LeetCode]166. Fraction to Recurring Decimal
Problem DescriptionGiven two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in p原创 2016-03-06 15:17:30 · 290 阅读 · 0 评论 -
[LeetCode]94. Binary Tree Inorder Traversal
Problem Description[https://leetcode.com/problems/binary-tree-inorder-traversal/] Given a binary tree, return the inorder traversal of its nodes’ values.思路本来刚刚做完一题想撤来着,pick one 了这个!!! F! pick one 有毒!原创 2016-03-09 20:21:25 · 220 阅读 · 0 评论 -
[LeetCode]338. Counting Bits
Problem DescriptionGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array. [https:原创 2016-04-03 11:28:06 · 244 阅读 · 0 评论 -
[LeetCode]54. Spiral Matrix
Problem Description[https://leetcode.com/problems/spiral-matrix/] Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the follow原创 2016-04-17 21:25:12 · 301 阅读 · 0 评论 -
[LeetCode]130. Surrounded Regions
Problem Description[https://leetcode.com/problems/surrounded-regions/] Given a 2D board containing ‘X’ and ‘O’, capture all regions surrounded by ‘X’.A region is captured by flipping all ‘O’s into ‘X’原创 2016-04-13 15:00:48 · 823 阅读 · 0 评论 -
[LeetCode]63. Unique Paths II
Problem Description[https://leetcode.com/problems/unique-paths-ii/] Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle原创 2016-04-09 15:17:48 · 494 阅读 · 0 评论 -
[LeetCode]304. Range Sum Query 2D - Immutable
Problem Description[https://leetcode.com/problems/range-sum-query-2d-immutable/] Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col原创 2016-04-13 13:53:32 · 271 阅读 · 0 评论 -
[LeetCode]80. Remove Duplicates from Sorted Array II
Problem Description[https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/] Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted a原创 2016-04-13 13:30:21 · 253 阅读 · 0 评论 -
[LeetCode]109. Convert Sorted List to Binary Search Tree
Problem Description[https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/] Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced B原创 2016-04-08 20:01:24 · 251 阅读 · 0 评论 -
[LeetCode]31. Next Permutation
Problem Description[https://leetcode.com/problems/next-permutation/] Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrange原创 2016-04-12 14:53:35 · 243 阅读 · 0 评论 -
[LeetCode]230. Kth Smallest Element in a BST
Problem Description[https://leetcode.com/problems/kth-smallest-element-in-a-bst/] Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.思路既然可能找很多遍,不如直接做一个有序的数原创 2016-04-12 14:26:19 · 279 阅读 · 0 评论 -
[LeetCode]120. Triangle
Problem Description[https://leetcode.com/problems/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.思路DP hahaha,我的原创 2016-04-07 16:01:41 · 284 阅读 · 0 评论 -
[LeetCode]22. Generate Parentheses
Problem Description[https://leetcode.com/problems/generate-parentheses/] Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3原创 2016-04-07 15:48:17 · 240 阅读 · 0 评论 -
[LeetCode]28. Implement strStr()
Problem DescriptionImplement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. [https://leetcode.com/problems/implement-strstr/]思路其实不用K原创 2016-02-29 21:03:10 · 240 阅读 · 0 评论 -
[LeetCode]208. Implement Trie (Prefix Tree)
Problem Description[https://leetcode.com/problems/implement-trie-prefix-tree/] Implement a trie with insert, search, and startsWith methods.思路没啥好说的,看代码就好惹。。Codepackage q208;import java.util.LinkedList原创 2016-04-06 15:52:46 · 384 阅读 · 0 评论 -
[LeetCode]50. Pow(x, n)
Problem Description[https://leetcode.com/problems/powx-n/] Implement pow(x, n).思路不明白这种题为什么会是mid的。。。Codepackage q050;public class Solution { public double myPow(double x, int n) { if (n ==原创 2016-04-06 14:33:52 · 558 阅读 · 0 评论 -
[LeetCode]334. Increasing Triplet Subsequence
Problem Description[https://leetcode.com/problems/increasing-triplet-subsequence/] Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the原创 2016-04-05 18:21:31 · 328 阅读 · 0 评论 -
[LeetCode]29. Divide Two Integers
Problem Description[https://leetcode.com/problems/divide-two-integers/] Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路没啥好说的,最讨厌做有关int范原创 2016-04-05 18:00:28 · 289 阅读 · 0 评论 -
[LeetCode]309. Best Time to Buy and Sell Stock with Cooldown
Problem Description[https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/] Say you have an array for which the ith element is the price of a given stock on day i.Design an algor原创 2016-04-04 17:39:42 · 677 阅读 · 0 评论 -
[LeetCode]114. Flatten Binary Tree to Linked List
Problem DescriptionGiven a binary tree, flatten it to a linked list in-place. [https://leetcode.com/problems/flatten-binary-tree-to-linked-list/]思路先序遍历,然后按个保存就行了。。。 左右不分真的不利于手写代码。。。要不是调试一下就是反的了。。。Cod原创 2016-04-03 14:26:27 · 263 阅读 · 0 评论 -
[LeetCode]131. Palindrome Partitioning
Problem DescriptionGiven a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = “aab”, Return[原创 2016-03-06 14:25:28 · 286 阅读 · 0 评论 -
[LeetCode]137. Single Number II
Problem DescriptionGiven an array of integers, every element appears three times except for one. Find that single one. [https://leetcode.com/problems/single-number-ii/]原创 2016-03-06 13:57:31 · 275 阅读 · 0 评论 -
[LeetCode]221. Maximal Square
Problem DescriptionGiven a 2D binary matrix filled with 0’s and 1’s, find the largest square containing all 1’s and return its area. [https://leetcode.com/problems/maximal-square/]原创 2016-03-02 15:58:55 · 234 阅读 · 0 评论