LeetCode
Frontier_Setter
这个作者很懒,什么都没留下…
展开
-
[LeetCode] (medium) 2. Add Two Numbers
https://leetcode.com/problems/add-two-numbers/You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain ...原创 2019-01-31 22:52:12 · 87 阅读 · 0 评论 -
[LeetCode] (medium) 3. Longest Substring Without Repeating Characters
https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, find the length of the longest substringwithout repeating characters.Example 1:Input: "abcabcbb"...原创 2019-01-31 23:52:36 · 80 阅读 · 0 评论 -
[LeetCode] (medium) 8. String to Integer (atoi)
https://leetcode.com/problems/string-to-integer-atoi/Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first no...原创 2019-02-02 01:33:40 · 72 阅读 · 0 评论 -
[LeetCode] (medium) 11. Container With Most Water
https://leetcode.com/problems/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...原创 2019-02-02 02:25:25 · 83 阅读 · 0 评论 -
[LeetCode] (medium) 15. 3Sum
https://leetcode.com/problems/3sum/Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero....原创 2019-02-02 16:36:28 · 87 阅读 · 0 评论 -
[LeetCode] (medium) 17. Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is gi...原创 2019-02-02 16:49:10 · 97 阅读 · 0 评论 -
[LeetCode] (medium) 19. Remove Nth Node From End of List
https://leetcode.com/problems/remove-nth-node-from-end-of-list/Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4...原创 2019-02-02 17:13:02 · 78 阅读 · 0 评论 -
[LeetCode] (medium) 105. Construct Binary Tree from Preorder and Inorder Traversal
https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplica...原创 2019-02-14 19:00:40 · 143 阅读 · 0 评论 -
[LeetCode] (medium) 127. Word Ladder
https://leetcode.com/problems/word-ladder/Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such ...原创 2019-02-14 21:39:50 · 164 阅读 · 0 评论 -
[LeetCode] (medium) 29. Divide Two Integers
https://leetcode.com/problems/divide-two-integers/submissions/Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quoti...原创 2019-02-04 20:57:38 · 142 阅读 · 0 评论 -
[LeetCode] (medium) 33. Search in Rotated Sorted Array
https://leetcode.com/problems/search-in-rotated-sorted-array/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...原创 2019-02-04 21:47:33 · 620 阅读 · 0 评论 -
[LeetCode] (medium) 34. Find First and Last Position of Element in Sorted Array
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/Given an array of integers nums sorted in ascending order, find the starting and ending position of a given tar...原创 2019-02-04 22:07:06 · 86 阅读 · 0 评论 -
[LeetCode] (medium) 46. Permutations
https://leetcode.com/problems/permutations/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]...原创 2019-02-05 00:22:05 · 101 阅读 · 0 评论 -
[LeetCode] (easy) 189.Rotate Array
https://leetcode.com/problems/rotate-array/Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]E...原创 2019-01-29 20:30:02 · 112 阅读 · 0 评论 -
[LeetCode] (easy) 204. Count Primes
https://leetcode.com/problems/count-primes/Count the number of prime numbers less than a non-negative number, n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, ...原创 2019-01-29 21:46:20 · 152 阅读 · 0 评论 -
[LeetCode] (medium) 138. Copy List with Random Pointer
https://leetcode.com/problems/copy-list-with-random-pointer/A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Retu...原创 2019-02-15 18:07:56 · 152 阅读 · 2 评论 -
[LeetCode] (medium) 139. Word Break
https://leetcode.com/problems/word-break/Given a non-empty string s and a dictionary wordDict containing a list of non-emptywords, determine if s can be segmented into a space-separated sequence of...原创 2019-02-15 20:30:46 · 131 阅读 · 0 评论 -
[LeetCode] (medium) 148. Sort List
https://leetcode.com/problems/sort-list/Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:In...原创 2019-02-15 22:40:31 · 69 阅读 · 0 评论 -
[LeetCode] (easy) 237. Delete Node in a Linked List
https://leetcode.com/problems/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 = ...原创 2019-01-30 19:44:39 · 126 阅读 · 0 评论 -
[LeetCode] (medium) 152. Maximum Product Subarray
https://leetcode.com/problems/maximum-product-subarray/Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Exa...原创 2019-02-16 19:37:07 · 87 阅读 · 0 评论 -
[LeetCode] (medium) 162. Find Peak Element
https://leetcode.com/problems/find-peak-element/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 retur...原创 2019-02-16 19:56:47 · 94 阅读 · 0 评论 -
[LeetCode] (medium) 210. Course Schedule II
https://leetcode.com/problems/course-schedule-ii/There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have ...原创 2019-02-16 23:26:03 · 111 阅读 · 0 评论 -
[LeetCode] (medium) 50. Pow(x, n)
https://leetcode.com/problems/powx-n/Implement pow(x, n), which calculates x raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output:...原创 2019-02-11 14:23:58 · 113 阅读 · 0 评论 -
[LeetCode] (medium) 55. Jump Game
https://leetcode.com/problems/jump-game/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 jum...原创 2019-02-11 15:46:26 · 127 阅读 · 0 评论 -
[LeetCode] (medium) 227. Basic Calculator II
https://leetcode.com/problems/basic-calculator-ii/Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operato...原创 2019-02-17 18:01:48 · 101 阅读 · 0 评论 -
[LeetCode] (medium) 75. Sort Colors
https://leetcode.com/problems/sort-colors/Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order r...原创 2019-02-11 20:06:05 · 110 阅读 · 0 评论 -
[LeetCode] (medium) 236. Lowest Common Ancestor of a Binary Tree
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA ...原创 2019-02-17 20:50:15 · 172 阅读 · 0 评论 -
[LeetCode] (medium) 240. Search a 2D Matrix II
https://leetcode.com/problems/search-a-2d-matrix-ii/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 so...原创 2019-02-17 22:16:00 · 224 阅读 · 0 评论 -
[LeetCode] (medium) 279. Perfect Squares
https://leetcode.com/problems/perfect-squares/Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.Example 1:Input: n = 12...原创 2019-02-17 22:57:04 · 124 阅读 · 0 评论 -
[LeetCode] (medium) 289. Game of Life
https://leetcode.com/problems/game-of-life/According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Hort...原创 2019-02-18 14:04:35 · 90 阅读 · 0 评论 -
[LeetCode] (medium) 322. Coin Change
https://leetcode.com/problems/coin-change/You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to ...原创 2019-02-18 15:04:39 · 388 阅读 · 0 评论 -
[LeetCode] (medium) 324. Wiggle Sort II
https://leetcode.com/problems/wiggle-sort-ii/Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....Example 1:Input: nums = [1, 5, 1, 1, 6, 4]Out...原创 2019-02-18 16:29:15 · 81 阅读 · 0 评论 -
[LeetCode] (medium) 328. Odd Even Linked List
https://leetcode.com/problems/odd-even-linked-list/Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and no...原创 2019-02-18 16:45:23 · 86 阅读 · 0 评论 -
[LeetCode] (medium) 378. Kth Smallest Element in a Sorted Matrix
https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the mat...原创 2019-02-18 20:30:23 · 198 阅读 · 0 评论 -
[LeetCode] (medium) 81. Search in Rotated Sorted Array II
https://leetcode.com/problems/search-in-rotated-sorted-array-ii/Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e.,[0,0,1,2,2,5,6]might become[...原创 2019-02-28 14:17:18 · 105 阅读 · 0 评论 -
[LeetCode] (medium) 91. Decode Ways
https://leetcode.com/problems/decode-ways/A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given a non-emp...原创 2019-02-13 17:08:39 · 116 阅读 · 0 评论 -
[LeetCode] (medium) 98. Validate Binary Search Tree
https://leetcode.com/problems/validate-binary-search-tree/Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node ...原创 2019-02-13 21:37:23 · 122 阅读 · 0 评论 -
[LeetCode] (medium) 18. 4Sum
https://leetcode.com/problems/4sum/Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets i...原创 2019-02-25 10:48:06 · 95 阅读 · 0 评论 -
[LeetCode] (medium) 24. Swap Nodes in Pairs
https://leetcode.com/problems/swap-nodes-in-pairs/Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list's nodes, only nodes itself may b...原创 2019-02-25 11:04:50 · 86 阅读 · 0 评论 -
[LeetCode] (medium) 31. Next Permutation
https://leetcode.com/problems/next-permutation/Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possi...原创 2019-02-25 11:28:34 · 100 阅读 · 0 评论