![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 60
rickdiculous
这个作者很懒,什么都没留下…
展开
-
75. Sort Colors
Given 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 will use the integers原创 2017-06-22 08:59:15 · 223 阅读 · 0 评论 -
289. Game of Life
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m原创 2017-02-23 16:45:49 · 177 阅读 · 0 评论 -
474. Ones and Zeroes
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s and n 1s respectively. On the ot原创 2017-02-23 15:01:45 · 166 阅读 · 0 评论 -
313. Super Ugly Number
Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13,原创 2017-02-22 15:01:46 · 174 阅读 · 0 评论 -
48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).创建一个数组,直接把元素放到合适的位置。public class Solution { public void rotate(int[][] matrix) { i原创 2017-02-22 09:50:31 · 162 阅读 · 0 评论 -
64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.非常简单的动态规划问题public class Solution { pu原创 2017-02-21 20:41:23 · 150 阅读 · 0 评论 -
215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.原创 2017-02-21 16:59:08 · 181 阅读 · 0 评论 -
240. Search a 2D Matrix II +74. Search a 2D Matrix
Write 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 in ascending from left to right.Integers in原创 2017-02-21 11:23:16 · 160 阅读 · 0 评论 -
78. Subsets
Given 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:[ [3], [1],原创 2017-02-20 21:52:28 · 166 阅读 · 0 评论 -
416. Partition Equal Subset Sum
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array原创 2017-02-20 21:18:02 · 157 阅读 · 0 评论 -
40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums toT.Each number in C may only be used once in the combinat原创 2017-02-20 20:24:13 · 143 阅读 · 0 评论 -
300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], ther原创 2017-02-20 14:57:29 · 170 阅读 · 0 评论 -
334. Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] ar原创 2017-02-20 10:40:02 · 138 阅读 · 0 评论 -
274. H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikipedia: "A原创 2017-02-28 16:59:17 · 215 阅读 · 0 评论 -
473. Matchsticks to Square
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You shoul原创 2017-02-28 16:23:53 · 209 阅读 · 0 评论 -
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原创 2017-02-28 14:35:44 · 179 阅读 · 0 评论 -
39. Combination Sum
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be原创 2017-02-23 17:01:35 · 163 阅读 · 0 评论 -
11. 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,原创 2017-02-24 11:22:17 · 146 阅读 · 0 评论 -
399. Evaluate Division
Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answ原创 2017-03-03 14:58:36 · 200 阅读 · 0 评论 -
189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].用三个反转,空间复杂度为O(1)public class Solution {原创 2017-06-04 11:43:54 · 195 阅读 · 0 评论 -
216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Example 1:Inpu原创 2017-01-11 17:01:51 · 171 阅读 · 0 评论 -
380. Insert Delete GetRandom O(1)
Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the set if not already present.remove(val): Removes an item val from the原创 2017-02-18 22:15:12 · 196 阅读 · 0 评论 -
442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without ex原创 2016-12-25 14:54:11 · 126 阅读 · 0 评论 -
581. Shortest Unsorted Continuous Subarray
Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to fin原创 2017-06-02 15:54:07 · 349 阅读 · 0 评论 -
376. Wiggle Subsequence
A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either pos原创 2017-02-27 15:13:10 · 192 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
Follow 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 should return length = 5, with the first fi原创 2017-02-27 11:29:47 · 194 阅读 · 0 评论 -
542. 01 Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:0 0 00 1 00原创 2017-03-19 11:11:04 · 373 阅读 · 0 评论 -
450. Delete Node in a BST
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.Basically, the deletion can be divided i原创 2017-02-26 15:54:21 · 221 阅读 · 0 评论 -
73. Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.如果空间复杂度为O(m+n),那十分的简单。在要求O(1)的情况下,我们需要使用数组本身来记录0的位置。思考过程:使用m+n个数来分别记录需要清零的行和列,相当于在数组外额外增加一行和一列。所以原创 2017-02-26 14:20:14 · 277 阅读 · 0 评论 -
375. Guess Number Higher or Lower II
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number I pi原创 2017-02-25 18:37:19 · 182 阅读 · 0 评论 -
331. Verify Preorder Serialization of a Binary Tree
One 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 value such as #.原创 2017-02-25 15:05:17 · 176 阅读 · 0 评论 -
129. Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota原创 2017-02-25 11:15:23 · 230 阅读 · 0 评论 -
395. Longest Substring with At Least K Repeating Characters
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.Example 1:Input:s = "aaabb", k =原创 2017-02-25 10:36:31 · 161 阅读 · 0 评论 -
279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given原创 2017-02-24 18:04:16 · 169 阅读 · 0 评论 -
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],]原创 2017-02-19 14:17:24 · 230 阅读 · 0 评论 -
524. Longest Word in Dictionary through Deleting
Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, retur原创 2017-02-28 11:03:15 · 220 阅读 · 0 评论 -
90. Subsets II
Given 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 = [1,2,2], a sol原创 2017-02-28 09:37:21 · 205 阅读 · 0 评论 -
404. Sum of Left Leaves
递归方法: public int sumOfLeftLeaves(TreeNode root) { if(root==null){ return 0; } int sum=0; Stack stacknode= new Stack stacknode.push(root); w原创 2016-09-26 19:40:56 · 197 阅读 · 0 评论 -
226. Invert Binary Tree
递归方法: public TreeNode invertTree(TreeNode root) { TreeNode m; if(root==null){ return root; } else if(root.left==null&&root.right==null){ return r原创 2016-09-27 09:17:39 · 174 阅读 · 0 评论 -
383. Ransom Note
一开始没有看懂题目什么意思,原来是只要比较ransomNote和magazine中相对应字母的个数。可以用map 也可以用数组。public class Solution { public boolean canConstruct(String ransomNote, String magazine) { if(ransomNote==""||ransomNot原创 2016-10-08 22:15:12 · 172 阅读 · 0 评论