Attempted
weixin_39145266
这个作者很懒,什么都没留下…
展开
-
41 First Missing Positive
Given an unsorted integer array, find the smallest missingpositive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,8,9,11,12]Output:...原创 2020-01-06 11:03:15 · 137 阅读 · 0 评论 -
1223 Dice Roll Simulation
1 题目A die simulator generates a random number from 1 to 6 for each roll.You introduced a constraint to the generator such that it cannot roll the numberimore thanrollMax[i](1-indexed)consecuti...原创 2019-12-24 05:24:18 · 302 阅读 · 0 评论 -
341 Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Example 1:Input: [[1,1],2...原创 2019-07-07 18:05:08 · 97 阅读 · 0 评论 -
155 Min Stack
1 题目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()...原创 2019-05-07 15:25:23 · 175 阅读 · 0 评论 -
232 Implement Queue using Stacks
1 题目Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front elemen...原创 2019-05-06 17:46:21 · 71 阅读 · 0 评论 -
283 Move Zeroes
1 题目Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:...原创 2019-05-06 15:20:24 · 63 阅读 · 0 评论 -
211 Add and Search Word - Data structure design
1 题目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 l...原创 2019-04-24 14:20:38 · 73 阅读 · 0 评论 -
284 Peeking Iterator
1 题目Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will ...原创 2019-04-24 14:16:31 · 159 阅读 · 0 评论 -
240 Search a 2D Matrix II
1 题目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 i...原创 2019-04-24 14:02:53 · 74 阅读 · 0 评论 -
227 Basic Calculator II
1 题目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 sho...原创 2019-04-24 11:19:59 · 100 阅读 · 0 评论 -
223 Rectangle Area
1 题目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.Example:Input: A...原创 2019-04-23 17:10:57 · 89 阅读 · 0 评论 -
220 Contains Duplicate III
1 题目Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute diff...原创 2019-04-23 16:05:45 · 79 阅读 · 0 评论 -
179 Largest Number
1 题目Given a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: "210"Example 2:Input: [3,30,34,5,9]Output: "9534330"Note: T...原创 2019-04-23 15:51:07 · 83 阅读 · 0 评论 -
324 Wiggle Sort II
1 题目Given an unsorted arraynums, reorder it such thatnums[0] < nums[1] > nums[2] < nums[3]....Example 1:Input: nums = [1, 5, 1, 1, 6, 4]Output: One possible answer is [1, 4, 1, 5, 1...原创 2019-07-07 15:39:11 · 61 阅读 · 0 评论 -
334 Increasing Triplet Subsequence
1 题目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 existsi, j, ksuch thatarr[i]<...原创 2019-07-07 17:22:36 · 128 阅读 · 0 评论 -
647 Palindromic Substrings
1 题目Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they co...原创 2019-08-03 17:26:39 · 52 阅读 · 0 评论 -
518 Coin Change 2
1 题目You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite...原创 2019-07-30 23:00:22 · 86 阅读 · 0 评论 -
310 Minimum Height Trees
1 题目For an undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are call...原创 2019-07-06 19:27:45 · 79 阅读 · 0 评论 -
378 Kth Smallest Element in a Sorted Matrix Medium
1 题目Given anxnmatrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order,...原创 2019-07-10 20:37:32 · 76 阅读 · 0 评论 -
309 Best Time to Buy and Sell Stock with Cooldown
1 题目Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, bu...原创 2019-06-30 16:32:28 · 122 阅读 · 0 评论 -
307 Range Sum Query - Mutable
1 题目Given an integer arraynums, find the sum of the elements between indicesiandj(i≤j), inclusive.Theupdate(i, val)function modifiesnumsby updating the element at indexitoval.Examp...原创 2019-06-29 18:46:37 · 120 阅读 · 0 评论 -
416 Partition Equal Subset Sum
1 题目Given anon-emptyarray containingonly 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...原创 2019-07-14 12:08:11 · 79 阅读 · 0 评论 -
390 Elimination Game
1 题目There is a list of sorted integers from 1 ton. Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.Repeat the previous st...原创 2019-07-14 11:21:54 · 79 阅读 · 0 评论 -
382 Linked List Random Node
1 题目Given a singly linked list, return a random node's value from the linked list. Each node must have thesame probabilityof being chosen.Follow up:What if the linked list is extremely large an...原创 2019-07-13 22:22:17 · 68 阅读 · 0 评论 -
380 Insert Delete GetRandom O(1)
1 题目Design a data structure that supports all following operations inaverageO(1)time.insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val fro...原创 2019-07-13 20:33:16 · 67 阅读 · 0 评论 -
229 Majority Element II
1 题目Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Note: The algorithm should run in linear time and in O(1) space.Example 1:Input: [3,2,3]Output: [3...原创 2019-04-23 13:00:48 · 187 阅读 · 0 评论 -
207 Course Schedule
1 题目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...原创 2019-04-23 10:39:38 · 81 阅读 · 0 评论 -
264 Ugly Number II
1 题目Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example:Input: n = 10Output: 12Explanation: 1, 2, 3, 4, 5, 6, 8,...原创 2019-04-11 21:47:42 · 76 阅读 · 0 评论 -
279 Perfect Squares
1 题目Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4.E...原创 2019-04-08 15:47:35 · 95 阅读 · 0 评论 -
89 Gray Code
1 题目The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequenc...原创 2019-04-11 18:49:27 · 75 阅读 · 0 评论 -
98 Validate Binary Search Tree
1 题目Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key....原创 2019-04-01 17:49:11 · 62 阅读 · 0 评论 -
73 Set Matrix Zeroes
1 题目Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do itin-place.Example 1:Input: [ [1,1,1], [1,0,1], [1,1,1]]Output: [ [1,0,1], [0,0,0], [1,0,1]...原创 2019-03-29 09:18:33 · 56 阅读 · 0 评论 -
22 Generate Parentheses
1 题目Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:[ "((()))", "(()())", "(())()", "(...原创 2019-04-05 13:11:30 · 74 阅读 · 0 评论 -
187 Repeated DNA Sequences
1 题目All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA....原创 2019-04-04 23:13:26 · 92 阅读 · 0 评论 -
29 Divide Two Integers
1 题目Given two integersdividendanddivisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividingdividendbydivisor.The integer divisi...原创 2019-03-29 09:18:55 · 137 阅读 · 0 评论 -
287 Find the Duplicate Number
1 题目Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate numbe...原创 2019-03-30 12:25:01 · 86 阅读 · 0 评论 -
209 Minimum Size Subarray Sum
1 题目Given an array ofnpositive integers and a positive integers, find the minimal length of acontiguoussubarray of which the sum ≥s. If there isn't one, return 0 instead.Example:Input: s...原创 2019-03-30 11:52:54 · 50 阅读 · 0 评论 -
56 Merge Intervals
1 题目Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] ov...原创 2019-03-29 09:17:13 · 51 阅读 · 0 评论 -
127 Word Ladder
1 题目Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed ...原创 2019-04-12 13:55:29 · 108 阅读 · 0 评论 -
50 Pow(x, n)
Implementpow(x,n), which calculatesxraised to the powern(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, ...原创 2019-04-03 12:42:13 · 77 阅读 · 0 评论