Leetcode解题报告
w_t_youxi
这个作者很懒,什么都没留下…
展开
-
【数组】Leetcode编程题解:380. Insert Delete GetRandom O(1)
题目:Design a data structure that supports all following operations in averageO(1) time.insert(val): Inserts an item val to the set if not already present.remove(val): Removes an item val from原创 2017-02-28 20:49:56 · 235 阅读 · 0 评论 -
【分治算法】Leetcode编程题解:240. Search a 2D Matrix II Add to List
题目: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.Integer原创 2017-03-30 00:43:32 · 224 阅读 · 0 评论 -
【分治算法】Leetcode编程题解:169. Majority Element Add to List
题目:Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority elemen原创 2017-03-14 00:15:38 · 502 阅读 · 0 评论 -
【动态规划】Leetcode编程题解:121. Best Time to Buy and Sell Stock Add to List
题目:Say you have an array for which the ith 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 sto原创 2017-05-10 23:12:12 · 323 阅读 · 0 评论 -
【动态规划】Leetcode编程题解:523. Continuous Subarray Sum Add to List
题目:Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple ofk, that is, sums原创 2017-05-23 11:44:20 · 409 阅读 · 0 评论 -
【动态规划】Leetcode编程题解:516. Longest Palindromic Subsequence Add to List
题目:Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.样例:Example 1:Input: "bbbab"Output:4One possible longest原创 2017-05-23 19:48:45 · 456 阅读 · 0 评论 -
【动态规划】Leetcode编程题解:338. Counting Bits
题目:Given a non negative integer number num. For every numbersi in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.样例:For num = 5 you原创 2017-05-23 22:39:57 · 502 阅读 · 0 评论 -
【动态规划】Leetcode编程题解:70. Climbing Stairs
题目:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?提示:Given n will be a po原创 2017-05-07 16:36:54 · 380 阅读 · 0 评论 -
【动态规划】Leetcode编程题解:303. Range Sum Query - Immutable Add to List
题目:Given an integer array nums, find the sum of the elements between indicesi and j (i ≤ j), inclusive.样例:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRang原创 2017-05-07 19:31:49 · 235 阅读 · 0 评论 -
【动态规划】Leetcode编程题解:198. House Robber Add to List
题目: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原创 2017-05-07 23:41:47 · 521 阅读 · 0 评论 -
【分治算法】Leetcode编程题解:53. Maximum Subarray Add to List
题目: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原创 2017-03-29 20:33:56 · 422 阅读 · 0 评论 -
【数组】Leetcode编程题解:289. Game of Life Add to List
题目:According to the Wikipedia'sarticle: "The Game of Life, alsoknown simply as Life, is a cellularautomaton devised by the British mathematician John Horton Conway in1970."Given a board with m转载 2017-03-04 16:24:51 · 401 阅读 · 0 评论 -
【数组】Leetcode编程题解: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 extr原创 2017-02-23 18:02:47 · 240 阅读 · 0 评论 -
【数组】Leetcode编程题解:448. Find All Numbers Disappeared in an Array
题目:Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array. Co原创 2017-02-22 23:53:44 · 480 阅读 · 0 评论 -
【数组】Leetcode编程题解:485. Max Consecutive Ones Add to List
题目: Given a binary array, find the maximum number of consecutive 1s in this array. 样例: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s.原创 2017-02-22 18:45:34 · 290 阅读 · 0 评论 -
【数组】Leetcode编程题解:495. Teemo Attacking
题目: In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning原创 2017-02-22 17:24:40 · 255 阅读 · 0 评论 -
【数组】Leetcode编程题解:414. Third Maximum Number
题目:Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).样例:1.Input: [3, 2, 1]Outpu原创 2017-02-24 00:37:03 · 288 阅读 · 0 评论 -
【数组】Leetcode编程题解:215. Kth Largest Element in an Array Add to List
题目: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. 样例: Given [3,2,1,5,6,4] and k = 2, return 5. Note:原创 2017-02-24 17:21:23 · 218 阅读 · 0 评论 -
【数组】Leetcode编程题解:381. Insert Delete GetRandom O(1) - Duplicates allowed Add to List
题目:Design a data structure that supports all following operations in average O(1) time.Note: Duplicate elements are allowed. 1.insert(val): Inserts an item val to the collection.2.remove(val): R转载 2017-02-25 00:18:37 · 275 阅读 · 0 评论 -
【分治算法】Leetcode编程题解:493. Reverse Pairs Add to List
题目:Given an array nums, we call (i, j) an important reverse pair ifi and nums[i] > 2*nums[j].You need to return the number of important reverse pairs in the given array.样例:1. Input: [1,转载 2017-03-04 16:10:33 · 567 阅读 · 0 评论 -
Leetcode编程题解:494. Target Sum
题目:You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols+ and -. For each integer, you should choose one from + and - as its new symbol. Find原创 2017-06-03 20:37:42 · 256 阅读 · 0 评论