![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 66
chuandalishuo
这个作者很懒,什么都没留下…
展开
-
209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3原创 2016-10-22 02:25:28 · 157 阅读 · 0 评论 -
287. Find the Duplicate Number
Given an array nums 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 number,原创 2016-11-01 01:18:37 · 145 阅读 · 0 评论 -
371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.思路:a^b异或等于无进位的加法,(a&b)解法一:public class Solution {原创 2016-11-01 00:15:57 · 147 阅读 · 0 评论 -
205. Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot原创 2016-10-21 09:13:03 · 144 阅读 · 0 评论 -
204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.思路: 从前向后扫描,第一次遇到没标记的应该是没有因子的质数。然后把后面所有这个质数的倍数都标记了。 public int countPrimes(int n) { if(n<2) retur原创 2016-10-21 08:54:44 · 141 阅读 · 0 评论 -
203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** * Definition for si原创 2016-10-20 07:27:44 · 158 阅读 · 0 评论 -
202. Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares原创 2016-10-20 07:23:00 · 176 阅读 · 0 评论 -
201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.思路:从左到右比较m和n的二进制数,相同的base加起来,直到出现不同的base,停止比较,因为后面一定是0,1交错的,而前面的一定是相同的(比较过来的),只要返回这些相同部分。public class原创 2016-10-20 06:59:38 · 156 阅读 · 0 评论 -
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 assu原创 2016-10-20 05:25:37 · 147 阅读 · 0 评论 -
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 house原创 2016-10-20 04:59:55 · 166 阅读 · 0 评论 -
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 the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000原创 2016-10-20 02:37:21 · 150 阅读 · 0 评论 -
171. Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 public c原创 2016-10-05 09:19:11 · 171 阅读 · 0 评论 -
121.122.123.188. Best Time to Buy and Sell Stock I II III IV
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2016-10-18 08:23:58 · 273 阅读 · 0 评论 -
373. Find K Pairs with Smallest Sums
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.Define a pair (u,v) which consists of one element from the first array and one element from the second a原创 2016-11-08 09:00:24 · 158 阅读 · 0 评论 -
283. Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2016-10-18 07:48:28 · 133 阅读 · 0 评论 -
190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2016-10-18 02:28:22 · 240 阅读 · 0 评论 -
223. Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota原创 2016-10-27 07:48:56 · 167 阅读 · 0 评论 -
30. Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and原创 2016-11-01 15:15:46 · 152 阅读 · 0 评论 -
164. Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements原创 2016-11-13 05:00:17 · 213 阅读 · 0 评论 -
146. 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原创 2016-12-09 14:04:33 · 211 阅读 · 0 评论 -
211. Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only lett原创 2016-12-09 08:25:07 · 255 阅读 · 0 评论 -
208. Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.class TrieNode { boolean isWord = false; // Stri原创 2016-12-09 08:23:32 · 173 阅读 · 0 评论 -
274,275. H-Index I, II
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原创 2016-12-08 13:09:40 · 219 阅读 · 0 评论 -
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"]/**原创 2016-12-05 10:48:47 · 170 阅读 · 0 评论 -
297. Serialize and Deserialize Binary Tree
Serialization 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 connection link to be原创 2016-12-05 10:15:43 · 149 阅读 · 0 评论 -
10. 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原创 2016-12-05 07:58:50 · 280 阅读 · 0 评论 -
301. Remove Invalid Parentheses
题目:Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses原创 2016-12-05 04:46:37 · 180 阅读 · 0 评论 -
91. Decode Ways
A 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 digits, determine the total nu原创 2016-12-05 03:04:28 · 201 阅读 · 0 评论 -
314. Binary Tree Vertical Order Traversal
题目:Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be fr原创 2016-12-04 08:59:10 · 207 阅读 · 0 评论 -
325. Maximum Size Subarray Sum Equals k
题目Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.Example 1:Given nums = [1, -1, 5, -2, 3], k = 3,return 4.原创 2016-12-04 08:45:51 · 209 阅读 · 0 评论 -
207,210. Course Schedule I, II
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2016-10-21 16:16:21 · 256 阅读 · 0 评论 -
221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0原创 2016-12-10 16:39:14 · 188 阅读 · 0 评论 -
32. 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 parentheses substring is "()",原创 2016-11-03 01:07:03 · 165 阅读 · 0 评论 -
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原创 2016-11-02 16:19:50 · 198 阅读 · 0 评论 -
394. Decode String
Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is原创 2016-11-17 02:28:29 · 167 阅读 · 0 评论 -
217, 219,220. Contains Duplicate I, II, III
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2016-10-27 01:40:41 · 273 阅读 · 0 评论 -
166. Fraction to Recurring Decimal
Given 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 parentheses.原创 2016-09-30 05:15:58 · 133 阅读 · 0 评论 -
162. Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in原创 2016-09-29 00:29:59 · 137 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2016-04-28 14:01:52 · 214 阅读 · 0 评论 -
19. Remove Nth Node From End of List
题目:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the原创 2016-04-28 01:19:42 · 172 阅读 · 0 评论