
LeetCode
文章平均质量分 53
ChuanjieZhu
这个作者很懒,什么都没留下…
展开
-
Remove Duplicates from Sorted List II(LeetCode)
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1->...原创 2018-08-23 12:23:00 · 179 阅读 · 0 评论 -
Remove Duplicates from Sorted List(LeetCode)
Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1-...原创 2018-08-23 11:55:43 · 155 阅读 · 0 评论 -
Intersection of Two Linked Lists(LeetCode)
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ ...原创 2018-08-23 11:26:22 · 205 阅读 · 0 评论 -
Reverse Linked List II(LeetCode)
Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5-...原创 2018-08-23 10:33:33 · 210 阅读 · 0 评论 -
Reverse Linked List(LeetCode)
Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or recursi...原创 2018-08-22 21:55:43 · 303 阅读 · 0 评论 -
Linked List Cycle II(LeetCode)
Given 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 extra space?判断链表知否存在环...原创 2018-08-22 17:11:58 · 202 阅读 · 0 评论 -
Linked List Cycle(LeetCode)
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?给你一个链表,让你在原地判断这个链表有没有环。 思路:使用快慢指针法。遍历,如果没有环,快指针最终指向NULL,也就是结尾,如果有环,慢指针最终会追上快指针。...原创 2018-08-22 16:06:52 · 219 阅读 · 0 评论 -
Jump Game(LeetCode)
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 if you ar...原创 2018-07-08 16:13:10 · 227 阅读 · 0 评论 -
Combination Sum IV(LeetCode)
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The possible ...原创 2018-07-08 15:05:49 · 258 阅读 · 0 评论 -
Combination Sum III(LeetCode)
Find 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 numbers.Note:All numbers will be p...原创 2018-07-08 10:36:53 · 200 阅读 · 0 评论 -
Combination Sum II(LetCode)
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidates may o...原创 2018-07-08 09:55:15 · 156 阅读 · 0 评论 -
Permutation Sequence(LeetCode)
The set [1,2,3,...,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence for n = 3:"123""132""213""231""312""321"Giv原创 2018-07-07 22:01:34 · 171 阅读 · 0 评论 -
Permutations II(LeetCode)
Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]这一题和上一题类似,就是数组里有重复的元素。思路:递归+深度优先搜...原创 2018-07-07 17:40:11 · 245 阅读 · 0 评论 -
Permutations(LeetCode)
Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]求全排列。思路:递归+深度优先搜索因为排列要使用所有数...原创 2018-07-07 17:19:08 · 547 阅读 · 0 评论 -
Combination Sum(Leetcode)
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same repeated...原创 2018-07-07 15:47:38 · 246 阅读 · 0 评论 -
Combinations(LeetCode)
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.Example:Input: n = 4, k = 2Output:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]求组合数。思路:递归+深度优先搜索(...原创 2018-07-06 22:33:33 · 255 阅读 · 0 评论 -
Reverse Integer(Leetcode)
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with an envir...原创 2018-06-30 22:21:06 · 161 阅读 · 0 评论 -
Basic Calculator II(Leetcode)
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 should trunc...原创 2018-06-30 22:19:12 · 162 阅读 · 0 评论 -
Basic Calculator(LeetCode)
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spac...原创 2018-06-30 22:18:26 · 281 阅读 · 0 评论 -
Add Binary(LeetCode)
Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "100"Example 2:Inp...原创 2018-06-30 22:17:12 · 142 阅读 · 0 评论 -
Number of 1 Bits / Power of Two(LeetCode)
Given an integer, write a function to determine if it is a power of two.Example 1:Input: 1Output: trueExample 2:Input: 16Output: trueExample 3:Input: 218Output: false判断一个数是不是2的次幂。思路:主要是利用2的整数幂的二进制只...原创 2018-05-16 16:37:33 · 139 阅读 · 0 评论 -
Missing Number(LeetCode)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example 1:Input: [3,0,1]Output: 2Example 2:Input: [9,6,4,2,3,5,7,0,1]Output: 8N...原创 2018-05-16 15:57:39 · 195 阅读 · 0 评论 -
Find Peak Element(LeetCode)
A peak element is an element that is greater than its neighbors.Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.The array may contain multiple peaks, in ...原创 2018-05-16 13:39:22 · 229 阅读 · 0 评论 -
Search Insert Position(LeetCode)
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Exam...原创 2018-05-16 12:44:20 · 139 阅读 · 0 评论 -
Search for a Range(LeetCode)
Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the tar...原创 2018-05-15 23:04:11 · 282 阅读 · 0 评论 -
Search a 2D Matrix II(LeetCode)
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 in each col...原创 2018-05-15 22:04:03 · 192 阅读 · 0 评论 -
Search a 2D Matrix(LeetCode)
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 is ...原创 2018-05-14 14:35:59 · 157 阅读 · 0 评论 -
Palindrome Number(LeetCode)
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input: -121Output: falseExplanation: F...原创 2018-05-14 13:34:41 · 255 阅读 · 0 评论 -
Maximal Rectangle(LeetCode)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.Example:Input:[ ["1","0","1","0","0"], ["1","0","1",&a原创 2018-05-14 11:55:56 · 194 阅读 · 0 评论 -
Largest Rectangle in Histogram(LeetCode)
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar...原创 2018-05-14 10:21:38 · 168 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array II (LeetCode)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find the minimum element.The array may contain dupl...原创 2018-05-14 09:29:58 · 203 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array(LeetCode)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find the minimum element.You may assume no duplicat...原创 2018-05-04 13:34:48 · 308 阅读 · 0 评论 -
3Sum Closest(LeetCode)
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly...原创 2018-05-04 10:58:17 · 142 阅读 · 0 评论 -
3Sum(LeetCode)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must be in...原创 2018-05-04 10:20:52 · 188 阅读 · 0 评论 -
2Sum(LeetCode)
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where i...原创 2018-05-04 09:32:30 · 344 阅读 · 0 评论 -
Merge Sorted Array(LeetCode)
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note: You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and...原创 2018-05-04 09:24:14 · 147 阅读 · 0 评论