
leetcode
文章平均质量分 69
TstsUgeg
这个作者很懒,什么都没留下…
展开
-
[leetcode] 114. Flatten Binary Tree to 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原创 2015-12-09 10:25:13 · 367 阅读 · 0 评论 -
[leetcode] 198. House Robber
You 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 that adjacent hou原创 2015-12-09 18:18:38 · 784 阅读 · 0 评论 -
[leetcode] 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> 4 and you are given the third node with va原创 2015-12-10 10:49:29 · 281 阅读 · 0 评论 -
[leetcode] 213. House Robber II
Note: This is an extension ofHouse Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This t原创 2015-12-09 18:37:16 · 545 阅读 · 0 评论 -
[leetcode] 200. Number of Islands
Given a 2d grid map of'1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may a原创 2015-12-10 16:45:54 · 378 阅读 · 0 评论 -
[leetcode] 31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2015-12-11 11:21:13 · 663 阅读 · 0 评论 -
[leetcode] 322. Coin Change
You are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of mon原创 2015-12-28 11:33:16 · 2344 阅读 · 0 评论 -
[leetcode] 124. Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. Th原创 2015-12-28 16:26:21 · 435 阅读 · 0 评论 -
[leetcode] 134. Gas Station
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 tank and it costscost[i] of gas to travel from station原创 2015-12-14 22:02:17 · 368 阅读 · 0 评论 -
[leetcode] 86. Partition List
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 should preserve the original relative order of the nodes in each原创 2015-12-15 16:29:00 · 339 阅读 · 0 评论 -
[leetcode] 16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2016-01-13 11:13:31 · 323 阅读 · 0 评论 -
[leetcode] 238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O原创 2015-12-15 10:08:23 · 288 阅读 · 0 评论 -
[leetcode] 5. Longest Palindromic Substring
Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofS is 1000, and there exists one unique longest palindromic substring.这道题是找出字符串的最长回文子串,题目原创 2015-12-17 10:19:42 · 335 阅读 · 0 评论 -
[leetcode] 61. Rotate List
Given a list, rotate the list to the right byk places, where k is non-negative.For example:Given1->2->3->4->5->NULL andk = 2,returnreturn4->5->1->2->3->NULL.这道题是循环右移链表,原创 2015-12-17 21:39:10 · 309 阅读 · 0 评论 -
[leetcode] 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]这道题是找出找出二叉树根节原创 2015-12-17 11:22:10 · 302 阅读 · 0 评论 -
[leetcode] 36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2016-01-19 09:55:59 · 391 阅读 · 0 评论 -
[leetcode] 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?这道原创 2015-11-16 10:14:57 · 364 阅读 · 0 评论 -
[leetcode] 1. Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, w原创 2015-11-17 14:33:24 · 477 阅读 · 0 评论 -
[leetcode] 174. Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p原创 2015-11-18 14:41:03 · 496 阅读 · 0 评论 -
[leetcode] 77. Combinations
Given 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], [2,3], [1,2], [1,3], [1,4],]原创 2015-11-18 16:35:44 · 413 阅读 · 0 评论 -
[leetcode] 121. Best Time to Buy and Sell Stock
Say you have an array for which theith element is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the s原创 2015-11-19 16:22:14 · 592 阅读 · 0 评论 -
[leetcode] 149. Max Points on a Line
Givenn points on a 2D plane, find the maximum number of points that lie on the same straight line.今天的题目是给出平面坐标系上的n个点,找出一条直线最多穿过多少这些已知的点。题目难度为Hard。乍看起来可能无从下手,不过通过直线坐标公式y=kx+b可原创 2015-11-20 21:31:27 · 527 阅读 · 0 评论 -
[leetcode] 188. Best Time to Buy and Sell Stock IV
Say you have an array for which theith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mostk transactions.Note:原创 2015-11-22 21:29:53 · 433 阅读 · 0 评论 -
[leetcode] 224. Basic Calculator
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open( and closing parentheses), the plus+ or minus sign-,non-negative integers and原创 2015-11-24 18:48:05 · 444 阅读 · 0 评论 -
[leetcode] 289. Game of Life
According to theWikipedia's article: "TheGame of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given aboard原创 2015-11-26 11:30:03 · 498 阅读 · 0 评论 -
[leetcode] 111. 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.这道题和二叉树相关,找出二叉树中从根节点到叶节点的最短路径长度,题目原创 2015-11-27 10:42:20 · 321 阅读 · 0 评论 -
[leetcode] 287. Find the Duplicate Number
Given an arraynums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate num原创 2015-11-19 15:18:00 · 543 阅读 · 0 评论 -
[leetcode] 123. 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原创 2015-11-22 20:27:44 · 438 阅读 · 0 评论 -
[leetcode] 141. Linked List Cycle
Problem:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra spact?这道题让检测链表是否存在回环,难度为Medium。最直观的想法是使用HashTable,每遍历一个节点检测是否已经存在,如果不存在把它存入H原创 2015-11-16 09:27:23 · 373 阅读 · 0 评论 -
[leetcode] 3. 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原创 2015-11-18 20:20:46 · 406 阅读 · 0 评论 -
[leetcode] 122. Best Time to Buy and Sell Stock II
Say you have an array for which theith 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 o原创 2015-11-20 11:07:18 · 410 阅读 · 0 评论 -
[leetcode] 282. Expression Add Operators
Given a string that contains only digits0-9 and a target value, return all possibilities to add binary operators (not unary) +,-, or * between the digits so they evaluate to the target val原创 2015-11-23 20:25:33 · 450 阅读 · 0 评论 -
[leetcode] 52. N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.这道题和第51题基本没有太大区别,题目难度为Hard。如果需要详细解释请看第51题(传送门),具体代码:class Solution原创 2015-11-24 10:14:34 · 390 阅读 · 0 评论 -
[leetcode] 201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.今天的题目是一道按位操作的题目,求一段数字区间中所有数字按位与的结果,题目难度为Medium。对于任意位,只要一个数中该位是0则结果中该位就是0,因为是按位与操作。我们再来看连续数据的特点,最大数和最小数原创 2015-11-24 11:11:24 · 324 阅读 · 0 评论 -
[leetcode] 227. Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division sh原创 2015-11-25 15:19:42 · 395 阅读 · 0 评论 -
[leetcode] 268. Missing Number
Given an array containingn distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Givennums = [0, 1, 3] return2.Note:Your algorith原创 2015-11-25 17:27:38 · 327 阅读 · 0 评论 -
[leetcode] 233. Number of Digit One
Given 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 in the follow原创 2015-11-26 20:42:31 · 501 阅读 · 0 评论 -
[leetcode] 96. Unique Binary Search Trees
Givenn, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's.1 3 3 2 1 \原创 2015-11-27 21:47:09 · 315 阅读 · 0 评论 -
[leetcode] 84. Largest Rectangle in Histogram
Givenn 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.Above is a histogram where widt原创 2015-11-30 15:29:02 · 412 阅读 · 0 评论 -
[leetcode] 191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit integer ’11' has binary representation000000原创 2015-11-30 21:27:33 · 321 阅读 · 0 评论