LeetCode题解
文章平均质量分 71
自己做LeetCode过程中的题解,欢迎大家一起交流。
link_98
越努力越幸运
展开
-
leetcode-628. Maximum Product of Three Numbers
628. Maximum Product of Three NumbersGiven an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example原创 2018-01-05 11:09:23 · 364 阅读 · 0 评论 -
leetcode-160. Intersection of Two Linked Lists
160. Intersection of Two Linked ListsWrite a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A:原创 2018-01-03 19:08:08 · 526 阅读 · 0 评论 -
leetcode-142. Linked List Cycle II
142. Linked List Cycle IIGiven a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using ext原创 2018-01-01 20:00:36 · 294 阅读 · 0 评论 -
leetcode-141. Linked List Cycle
141. Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?题意:判断一个链表是否为一个环?(能否使用O(1)的空间复杂度?)思路:在做过之前的题:287. Find the Duplicate Nu原创 2018-01-01 19:23:22 · 309 阅读 · 0 评论 -
leetcode-287. Find the Duplicate Number
287. Find the Duplicate NumberGiven 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原创 2017-12-27 22:17:38 · 534 阅读 · 0 评论 -
leetcode-752. Open the Lock
752. Open the LockYou have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap aro原创 2017-12-25 12:31:44 · 1710 阅读 · 0 评论 -
leetcode-751. IP to CIDR
751. IP to CIDRGiven a start IP address ip and a number of ips we need to cover n, return a representation of the range as a list (of smallest possible length) of CIDR blocks.A CIDR bloc原创 2017-12-25 12:28:41 · 4937 阅读 · 0 评论 -
leetcode-747. Largest Number Greater Than Twice of Others
747. Largest Number Greater Than Twice of OthersIn a given integer array nums, there is always exactly one largest element.Find whether the largest element in the array is at least twice as原创 2017-12-25 12:26:17 · 860 阅读 · 2 评论 -
leetcode-565. Array Nesting
565. Array NestingA 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 t原创 2017-12-23 10:18:31 · 360 阅读 · 0 评论 -
leetcode-121. Best Time to Buy and Sell Stock
121. Best Time to Buy and Sell StockSay 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, b原创 2017-12-21 09:58:24 · 314 阅读 · 0 评论 -
leetcode-216. Combination Sum III
216. Combination Sum IIIFind all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of nu原创 2017-12-14 21:13:00 · 397 阅读 · 0 评论 -
leeetcode-40. Combination Sum II
40. Combination Sum IIGiven a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only原创 2017-12-11 18:50:27 · 435 阅读 · 0 评论 -
leetcode- 39. Combination Sum
39. Combination Sumiven a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repe原创 2017-12-08 18:29:08 · 303 阅读 · 0 评论 -
leetcode-90. Subsets II
90. Subsets IIGiven a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For ex原创 2017-12-07 21:37:39 · 182 阅读 · 0 评论 -
leetcode-78. Subsets
78. SubsetsGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3],原创 2017-12-06 15:27:23 · 389 阅读 · 0 评论 -
leetcode-238. Product of Array Except Self
238. Product of Array Except SelfGiven 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[原创 2017-11-29 20:38:29 · 348 阅读 · 0 评论 -
leetcode- 442. Find All Duplicates in an Array
442. Find All Duplicates in an ArrayGiven 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 t原创 2017-11-27 12:44:43 · 374 阅读 · 0 评论 -
leetcode-100. Same Tree
100. Same TreeGiven two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the原创 2017-11-26 12:56:52 · 364 阅读 · 0 评论 -
leetcode-530. Minimum Absolute Difference in BST
530. Minimum Absolute Difference in BSTGiven a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1原创 2017-11-25 10:45:32 · 234 阅读 · 0 评论 -
leetcode-728. Self Dividing Numbers
728. Self Dividing NumbersA self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, a原创 2017-11-24 16:57:14 · 1714 阅读 · 0 评论 -
leetcode-387. First Unique Character in a String
387. First Unique Character in a StringGiven a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0原创 2017-11-22 18:42:21 · 609 阅读 · 0 评论 -
leetcode-167. Two Sum II - Input array is sorted
167. Two Sum II - Input array is sortedGiven an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function two原创 2017-11-21 15:35:36 · 403 阅读 · 0 评论 -
leetcode-169. Majority Element
leetcode-169. Majority Element Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-e原创 2017-11-21 09:00:11 · 285 阅读 · 0 评论 -
leetcode-455. Assign Cookies
455. Assign CookiesAssume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which i原创 2017-11-20 19:38:58 · 862 阅读 · 0 评论 -
<LeetCode>258. Add Digits
258. Add DigitsTotal Accepted: 79895 Total Submissions: 165648 Difficulty: EasyGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.原创 2016-03-21 12:26:36 · 348 阅读 · 0 评论 -
<LeetCode>575. Distribute Candies
575. Distribute CandiesGiven an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind.原创 2017-10-16 16:44:59 · 216 阅读 · 0 评论 -
LeetCode-104. Maximum Depth of Binary Tree
104. Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf原创 2017-10-27 10:33:46 · 189 阅读 · 0 评论 -
LeetCode-283. Move Zeroes
283. Move ZeroesGiven 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,原创 2017-11-05 19:56:05 · 155 阅读 · 0 评论 -
leetcode-697. Degree of an Array
697. Degree of an ArrayGiven a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find t原创 2017-11-11 15:52:32 · 516 阅读 · 0 评论 -
leetcode-349. Intersection of Two Arrays
349. Intersection of Two ArraysGiven two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element原创 2017-11-15 17:32:04 · 207 阅读 · 0 评论 -
<LeetCode> 292. Nim Game
这里是原题网址,点击我查看class Solution {public: bool canWinNim(int n) { if(n%4!=0) return true; else return false; }};仔细想想会发现:1,2,3个时,自己一定赢;4,自己一定输;5,6,7,自己一定赢;8,自己一定输原创 2016-03-20 16:38:13 · 303 阅读 · 0 评论 -
<LeetCode>344. Reverse String
344. Reverse String My SubmissionsQuestionEditorial SolutionTotal Accepted: 10975 Total Submissions: 18784 Difficulty: EasyWrite a function that takes a string as input and原创 2016-04-29 19:16:03 · 737 阅读 · 0 评论 -
<LeetCode>136. Single Number
这是原题描述:136. Single Number QuestionEditorial Solution My SubmissionsTotal Accepted: 136646Total Submissions:269614Difficulty: MediumGiven an array of integers,原创 2016-07-06 21:44:00 · 308 阅读 · 0 评论 -
<LeetCode>682. Baseball Game
You're now a baseball game point recorder.Given a list of strings, each string can be one of the 4 following types:Integer (one round's score): Directly represents the number of points you get原创 2017-10-12 20:14:57 · 302 阅读 · 0 评论 -
<LeetCode>557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contes原创 2017-10-12 20:49:53 · 195 阅读 · 0 评论 -
<LeetCode> 412. Fizz Buzz
412. Fizz BuzzWrite a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of原创 2017-10-16 19:03:28 · 255 阅读 · 0 评论 -
<LeetCode>566. Reshape the Matrix
566. Reshape the MatrixIn 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原创 2017-10-17 11:06:16 · 190 阅读 · 0 评论 -
<LeetCode>669. Trim a Binary Search Tree
669. Trim a Binary Search TreeGiven a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to c原创 2017-10-18 22:28:13 · 207 阅读 · 0 评论 -
<leetcode>463. Island Perimeter
463. Island PerimeterYou are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagona原创 2017-10-19 18:24:23 · 169 阅读 · 0 评论 -
<leetcode>496. Next Greater Element I
496. Next Greater Element IYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in原创 2017-10-19 22:35:14 · 177 阅读 · 0 评论