LeetCode刷题日志
leetcode刷题的个人题解和总结栏目
CrazyOnes
个人邮箱:crazyones201@163.com
展开
-
LeetCode 1——Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same ...原创 2018-09-17 19:59:53 · 178 阅读 · 0 评论 -
LeetCode 27——Remove Element
Given an arraynumsand a valueval, remove all instances of that valuein-placeand return the new length.Do not allocate extra space for another array, you must do this bymodifying the input arra...原创 2019-05-04 21:07:32 · 205 阅读 · 0 评论 -
LeetCode 75 —— SortColors
题目Given an array withnobjects colored red, white or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use th...原创 2019-05-09 19:53:26 · 208 阅读 · 0 评论 -
LeetCode 78——Subsets
Given a set ofdistinctintegers,nums, return all possible subsets (the power set).Note:The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[ [3], [...原创 2019-03-10 14:32:40 · 176 阅读 · 0 评论 -
LeetCode 122——Best Time to Buy and Sell Stock II
Say you have an array for which theelement 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 (i.e., buy one a...原创 2019-03-13 22:39:20 · 230 阅读 · 0 评论 -
LeetCode 167——Two Sum II - Input array is sorted
Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers ...原创 2019-03-18 21:04:22 · 236 阅读 · 0 评论 -
LeetCode 169——Majority Element
Given an array of sizen, 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 element alway...原创 2019-03-08 21:43:07 · 231 阅读 · 0 评论 -
LeetCode 217——Contains Duplicate(Arrays.sort()的速度体现)
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 i...原创 2019-03-13 14:48:19 · 245 阅读 · 0 评论 -
LeetCode 238——Product of Array Except Self
Given an arraynumsofnintegers wheren> 1, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Example:Input:[1,2,3,4]Output:[...原创 2019-03-03 14:00:04 · 215 阅读 · 0 评论 -
LeetCode 283——Move Zeroes
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:You ...原创 2019-03-05 02:02:08 · 176 阅读 · 0 评论 -
LeetCode 442——Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤n(n= size of array), some elements appeartwiceand others appearonce.Find all the elements that appeartwicein this array.Could you do it without extra ...原创 2019-03-03 16:30:53 · 230 阅读 · 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.Coul...原创 2019-03-05 15:56:32 · 160 阅读 · 0 评论 -
LeetCode 485——Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive ...原创 2019-03-02 13:35:52 · 166 阅读 · 0 评论 -
LeetCode 495——Teemo Attacking
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attackingascendingtime series towards Ashe and the poisoning tim...原创 2019-03-06 14:28:24 · 243 阅读 · 0 评论 -
LeetCode 565——Array Nesting
A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule below.Suppos...原创 2019-03-07 20:58:41 · 236 阅读 · 0 评论 -
LeetCode 566——Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dimen...原创 2019-03-01 16:58:42 · 188 阅读 · 0 评论 -
LeetCode 667——Beautiful Arrangement II
Given two integersnandk, you need to construct a list which containsndifferent positive integers ranging from1tonand obeys the following requirement:Suppose this list is [a1, a2, a3, ... , ...原创 2019-03-09 23:39:47 · 175 阅读 · 0 评论 -
LeetCode 769——Max Chunks To Make Sorted
Given an arrayarrthat is a permutation of[0, 1, ..., arr.length - 1], we split the array into some number of "chunks" (partitions), and individually sort each chunk. After concatenating them,the ...原创 2019-03-13 17:05:42 · 283 阅读 · 0 评论 -
LeetCode 896——Monotonic Array
An array is monotonic if it is either monotone increasing or monotone decreasing.An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone decreasing if for all...原创 2019-03-02 15:46:02 · 155 阅读 · 0 评论 -
LeetCode 976——Largest Perimeter Triangle
Given an arrayAof positive lengths, return the largest perimeter of a triangle withnon-zero area, formed from 3 of these lengths.If it is impossible to form anytriangle of non-zero area, return...原创 2019-03-01 21:18:22 · 226 阅读 · 0 评论 -
LeetCode 977——Squares of a Sorted Array
Given an array of integersAsorted in non-decreasing order,return an array of the squares of each number,also in sorted non-decreasing order.Example 1:Input: [-4,-1,0,3,10]Output: [0,1,9,1...原创 2019-02-25 20:44:31 · 342 阅读 · 0 评论