![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 71
kakitgogogo
这个作者很懒,什么都没留下…
展开
-
120. 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.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,原创 2016-04-12 15:47:10 · 253 阅读 · 0 评论 -
242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false. Note: You may assume the原创 2016-04-12 16:15:45 · 291 阅读 · 0 评论 -
53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has t原创 2016-04-12 16:36:37 · 298 阅读 · 0 评论 -
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 from left to right. •The first integer of each row原创 2016-04-12 17:04:02 · 309 阅读 · 0 评论 -
316. Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order am原创 2016-04-09 22:46:02 · 192 阅读 · 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.原创 2016-04-13 20:23:58 · 228 阅读 · 0 评论 -
190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.原创 2016-04-10 10:56:37 · 304 阅读 · 0 评论 -
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(n).For e原创 2016-04-13 23:10:28 · 290 阅读 · 0 评论 -
241. Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *Example 1Input: “2-原创 2016-04-10 21:10:52 · 289 阅读 · 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, ksuch that arr[i] < arr[j] < arr[原创 2016-04-25 16:32:58 · 206 阅读 · 0 评论 -
303. Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example: Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1 sumRange(2, 5) -> -1 sumRange(0, 5原创 2016-04-27 17:23:01 · 206 阅读 · 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 n = 13, return原创 2016-04-15 13:59:11 · 450 阅读 · 0 评论 -
219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.方法1:使用map(7原创 2016-04-15 14:43:44 · 200 阅读 · 0 评论 -
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?Write a function to determine if a given target is in the array.代码原创 2016-04-15 16:19:42 · 226 阅读 · 0 评论 -
264. Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly原创 2016-04-16 11:02:01 · 182 阅读 · 0 评论 -
263. Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it in原创 2016-04-16 11:07:12 · 201 阅读 · 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, 14, 16,原创 2016-04-16 11:16:09 · 194 阅读 · 0 评论 -
151. Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place in原创 2016-05-11 16:18:47 · 491 阅读 · 0 评论 -
155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2016-05-11 17:22:23 · 197 阅读 · 0 评论 -
330. Patching Array
Given 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 in the array. Retur原创 2016-04-30 00:11:18 · 205 阅读 · 0 评论 -
225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. empty() – Return whether原创 2016-04-17 13:22:22 · 202 阅读 · 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 \ 5 All root-to-leaf paths are:[“1->2->5”, “1->3”]代码:/** * Definition for a bin原创 2016-04-30 16:27:54 · 168 阅读 · 0 评论 -
228. Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”].题目要求找出连续的区域,遍历一次数组就可以得到结果代码原创 2016-04-30 17:20:57 · 181 阅读 · 0 评论 -
306. Additive Number
Additive 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 number in the sequence must be the sum of the preceding two.原创 2016-05-01 18:49:36 · 235 阅读 · 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 scie原创 2016-05-04 08:48:41 · 287 阅读 · 0 评论 -
201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4. m,n同时向右移位直到m和n相等,用k记录移了多少位原创 2016-04-19 22:45:15 · 205 阅读 · 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 assume原创 2016-04-20 00:13:31 · 346 阅读 · 0 评论 -
41. First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant原创 2016-05-14 15:39:35 · 187 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.求若干串字符串的最长共同前缀子串。直接每个字符串对比即可得到结果。代码:class Solution {public:string longestCommonPrefix(vector& strs){原创 2016-05-14 15:57:57 · 218 阅读 · 0 评论 -
55. Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2016-05-14 16:50:58 · 271 阅读 · 0 评论 -
49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note:原创 2016-05-14 17:32:12 · 297 阅读 · 0 评论 -
199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.原创 2016-05-04 12:17:31 · 177 阅读 · 0 评论 -
78. Subsets
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For原创 2016-05-04 15:18:29 · 336 阅读 · 0 评论 -
37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku原创 2016-05-15 16:50:53 · 722 阅读 · 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.For exam原创 2016-04-20 23:34:05 · 210 阅读 · 0 评论 -
315. Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new counts array.The counts array has the property where counts[i] is the number of smaller elements to the right ofnums[i].Example:原创 2016-05-05 22:06:28 · 967 阅读 · 0 评论 -
327. Count of Range Sum
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j), incl原创 2016-04-21 22:41:25 · 246 阅读 · 0 评论 -
349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.T原创 2016-05-18 15:17:13 · 2872 阅读 · 0 评论 -
290. Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2016-05-18 15:43:29 · 191 阅读 · 0 评论 -
275. H-Index II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?Hint:Expected runtime complexity is in O(log n) and the input is sorted.原创 2016-05-18 17:17:25 · 240 阅读 · 0 评论