
LeetCode
励志学好数据结构
哼哼
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode
对做过的题目进行粗略的划分。紫色是top100。树:LeetCode94:Binary Tree Inorder TraversalLeetCode144:Binary Tree Preorder TraversalLeetCode145:Binary Tree Postorder TraversalLeetCode96:Unique Binary Search Trees...原创 2018-10-29 17:26:04 · 736 阅读 · 0 评论 -
LeetCode01:two Sum
Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2018-09-14 11:22:52 · 170 阅读 · 0 评论 -
LeetCode442: 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 extra ...原创 2018-09-14 15:45:35 · 114 阅读 · 0 评论 -
LeetCode19: Remove Nth Node From End of List
LeetCode:链接参考链接:点这里Given a linked list, remove then-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the seco...原创 2018-10-29 17:24:15 · 236 阅读 · 0 评论 -
LeetCode15:3Sum
Given an arraynumsofnintegers, are there elementsa,b,cinnumssuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not cont...原创 2018-10-31 21:37:07 · 238 阅读 · 0 评论 -
LeetCode18:4Sum
Given an arraynumsofnintegers and an integertarget, are there elementsa,b,c, anddinnumssuch thata+b+c+d=target? Find all unique quadruplets in the array which gives the sum oftar...原创 2018-10-31 22:19:17 · 133 阅读 · 0 评论 -
LeetCode21: Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1-...原创 2018-10-30 10:20:09 · 224 阅读 · 0 评论 -
LeetCode141:Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?LeetCode:链接和剑指Offer_编程题55:链表中环的入口结点是一样的。快慢指针思想,慢指针一次走一步,快指针一次走两步,如果快慢指针相遇说明有环。但是在判断...原创 2018-10-30 10:34:12 · 262 阅读 · 0 评论 -
LeetCode142:Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note:Do not modify the linked list.Follow up:Can you solve it without using extra space?LeetCode:...原创 2018-10-30 10:45:53 · 191 阅读 · 0 评论 -
LeetCode206:Reverse Linked List
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-10-30 11:21:21 · 203 阅读 · 0 评论 -
LeetCode876:Middle of the Linked List
Given a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.Example 1:Input: [1,2,3,4,5]Output: ...原创 2018-10-30 11:42:19 · 277 阅读 · 0 评论 -
LeetCode16:3Sum Closest
Given an arraynumsofnintegers and an integertarget, find three integers innumssuch that the sum is closest totarget. Return the sum of the three integers. You may assume that each input would ...原创 2018-11-01 10:25:25 · 174 阅读 · 0 评论 -
LeetCode26:Remove Duplicates from Sorted Array
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifyi...原创 2018-11-01 22:23:18 · 196 阅读 · 0 评论 -
LeetCode27:Remove Element
Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input arra...原创 2018-11-01 23:00:25 · 179 阅读 · 0 评论 -
LeetCode118:Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output:...原创 2018-11-06 21:04:22 · 128 阅读 · 0 评论 -
LeetCode119:Pascal's Triangle II
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.Note that the row index starts from 0.In Pascal's triangle, each number is the sum of the two numbers ...原创 2018-11-06 21:31:08 · 133 阅读 · 0 评论 -
LeetCode11:Container With Most Water
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two...原创 2018-11-02 09:26:29 · 218 阅读 · 0 评论 -
LeetCode42:Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented by arra...原创 2018-11-02 10:24:13 · 107 阅读 · 0 评论 -
LeetCode35:Search Insert Position(二分法)
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....原创 2018-11-02 10:46:06 · 175 阅读 · 0 评论 -
LeetCode442: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 ...原创 2018-11-02 14:20:33 · 198 阅读 · 0 评论 -
LeetCode283: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 m...原创 2018-11-10 08:55:20 · 167 阅读 · 0 评论 -
LeetCode268:Missing Number(多种方法)
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]O...原创 2018-11-10 09:13:42 · 254 阅读 · 0 评论 -
LeetCode414. 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).Example 1:Input: [3, 2, 1]...原创 2018-11-10 09:36:08 · 133 阅读 · 0 评论 -
LeetCode448: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...原创 2018-11-10 10:16:44 · 167 阅读 · 0 评论 -
LeetCode121:Best Time to Buy and Sell Stock
Say 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 (i.e., buy one and sell one share of the stock),...原创 2018-11-07 21:56:28 · 246 阅读 · 0 评论 -
LeetCode122:Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy on...原创 2018-11-07 22:15:17 · 216 阅读 · 0 评论 -
LeetCode167: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 ...原创 2018-11-07 22:23:16 · 143 阅读 · 0 评论 -
LeetCode53:Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanati...原创 2018-11-05 14:42:07 · 240 阅读 · 0 评论 -
LeetCode62: Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo...原创 2018-11-05 15:27:00 · 188 阅读 · 0 评论 -
LeetCode63: Unique Paths II
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo...原创 2018-11-05 16:00:00 · 165 阅读 · 0 评论 -
LeetCode66:Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element...原创 2018-11-05 16:49:23 · 148 阅读 · 0 评论 -
LeetCode88:Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume tha...原创 2018-11-05 17:26:14 · 159 阅读 · 0 评论 -
LeetCode234:Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n) time a...原创 2018-11-13 09:44:56 · 220 阅读 · 0 评论 -
LeetCode237:Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Given linked list -- head = [4,5,1,9], which looks like following: 4 -> 5 -> 1...原创 2018-11-13 10:00:30 · 300 阅读 · 0 评论 -
LeetCode13:Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2018-11-13 10:34:21 · 196 阅读 · 0 评论 -
LeetCode14:Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["flower","flow","flight"]Output:...原创 2018-11-13 11:05:57 · 211 阅读 · 0 评论 -
LeetCode169: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 alwa...原创 2018-11-08 09:01:35 · 242 阅读 · 0 评论 -
LeetCode189:Rotate Array
Given an array, rotate the array to the right byksteps, wherekis non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1...原创 2018-11-08 09:54:37 · 169 阅读 · 0 评论 -
LeetCode217:Contains Duplicate
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...原创 2018-11-08 10:25:49 · 180 阅读 · 0 评论 -
LeetCode219:Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k....原创 2018-11-08 10:46:17 · 170 阅读 · 0 评论