Leetcode
文章平均质量分 85
凶猛小白兔�
这个作者很懒,什么都没留下…
展开
-
Leetcode 103: Binary Tree Zigzag Level Order Traversal
Question:Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given b...原创 2019-06-30 01:56:53 · 120 阅读 · 0 评论 -
Leetcode: 289. Game of Life
Question:Given a board with m by n cells, each cell has an initial state live (1) or dead (0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four r...原创 2019-06-11 03:45:28 · 112 阅读 · 0 评论 -
Leetcode: 146. LRU Cache
QuestionDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: getand put.get(key)- Get the value (will always be positive) of the key...原创 2019-06-04 10:49:51 · 116 阅读 · 0 评论 -
Leetcode: 695. Max Area of Island && Leetcode 200: Num of Islands
Question:Given a non-empty 2D array gridof 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid a...原创 2019-06-14 13:30:37 · 98 阅读 · 0 评论 -
Leetcode: 332. Reconstruct Itinerary
Question:Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK...原创 2019-06-03 05:19:56 · 96 阅读 · 0 评论 -
Leetcode: 121. Best Time to Buy and Sell Stock && 122. Best Time to Buy and Sell Stock II
121Question: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 o...原创 2019-06-08 08:18:03 · 150 阅读 · 0 评论 -
Leetcode: 238. Product of Array Except Self
QuestionGiven an array numsof n integers where n > 1, return an array output such that output[i]is equal to the product of all the elements of numsexcept nums[i].Example:Input: [1,2,3,4]Outp...原创 2019-06-08 02:01:32 · 94 阅读 · 0 评论 -
Leetcode: 448. Find All Numbers Disappeared in an Array
Question: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 arr...原创 2019-06-13 09:01:40 · 96 阅读 · 0 评论 -
Leetcode: 67. Add Binary
Question: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...原创 2019-06-01 03:31:18 · 87 阅读 · 0 评论 -
Leetcode 17: 17. Letter Combinations of a Phone Number
Question:Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.Example:Input: “23”Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf...原创 2019-05-29 01:55:24 · 111 阅读 · 0 评论 -
Leetcode: 283. Move Zeroes & 75. Sort Colors
Question:Given 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.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note...原创 2019-05-24 02:35:19 · 91 阅读 · 0 评论 -
Leetcode: 973. K Closest Points to Origin (customized comparator)
Question:We have a list of pointson the plane. Find the Kclosest points to the origin (0, 0).(Here, the distance between two points on a plane is the Euclidean distance.)You may return the answer ...原创 2019-06-05 01:37:10 · 152 阅读 · 0 评论 -
Leetcode: 56. Merge Intervals
Question:Given a collection of intervals, merge all overlapping intervals.Example:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] ov...原创 2019-06-05 02:32:03 · 104 阅读 · 0 评论 -
LeetCode: 82&83: Remove Duplicates from Sorted List II&I
QuestionGiven 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...原创 2019-06-25 05:20:12 · 94 阅读 · 0 评论 -
Binary Tree & Binary Search Tree
Binary TreeDefinition: at most two children node.Binary Tree Example:class TreeNode { int value; TreeNode* left; TreeNode* right;}基本知识点Tree TraversePre-order先打印自己的节点,然后打印左节点(recurse后变成当前节...原创 2019-06-29 01:17:23 · 489 阅读 · 0 评论 -
369. Plus One Linked List
QuestionGiven a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 ...原创 2019-06-27 02:40:41 · 122 阅读 · 0 评论 -
Leetcode 127: Word Ladder
Question:Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be chang...原创 2019-07-02 12:52:03 · 138 阅读 · 0 评论 -
Leetcode: 61. Rotate List
Question:Given a linked list, rotate the list to the right by k places, where k is non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NUL...原创 2019-06-23 14:32:04 · 106 阅读 · 0 评论 -
Leetcode: 341. Flatten Nested List Iterator
Question:Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list – whose elements may also be integers or other lists.Example 1:Input: [[...原创 2019-06-22 07:42:17 · 104 阅读 · 0 评论 -
Leetcode: 42. Trapping Rain Water
Question: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...原创 2019-06-22 06:52:56 · 116 阅读 · 0 评论 -
Leetcode: 240. 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 sorted in ascending from left to right.Integers in each ...原创 2019-06-17 10:51:16 · 78 阅读 · 0 评论 -
Leetcode: 347. Top K Frequent Elements
Question:Given a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Solution 1: Priority Queuepublic class Element{ int ...原创 2019-05-28 11:34:33 · 77 阅读 · 0 评论 -
Leetcode: 98. Validate Binary Search Tree
Question: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 contains only nodes with keys less than the node’s k...原创 2019-05-30 09:24:30 · 97 阅读 · 0 评论 -
Leetcode 160. Intersection of Two Linked Lists
Question:Write a program to find the node at which the intersection of two singly linked lists begins.Solution1: Two Pointerspublic class Solution { public ListNode getIntersectionNode(ListNode...原创 2019-01-16 13:09:25 · 80 阅读 · 0 评论 -
Leetcode: 138. Copy List with Random Pointer
Question: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.Return a deep copy of the list.Solution1:public class So...原创 2019-01-20 18:38:43 · 114 阅读 · 0 评论 -
Leetcode: 147. Insertion Sort List
Question:Sort a linked list using insertion sort.Algorithm of Insertion Sort:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.At each iterati...原创 2019-01-14 12:46:47 · 103 阅读 · 0 评论 -
Leetcode 142. Linked List Cycle II
Question:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.To represent a cycle in the given linked list, we use an integer pos which represents the posi...原创 2019-01-12 01:20:41 · 98 阅读 · 0 评论 -
Leetcode 771. Jewels and Stones
QuestionYou’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many o...原创 2019-01-02 15:39:02 · 162 阅读 · 0 评论 -
Leetcode 200. Number of Islands
QuestionGiven a 2d grid map of '1’s (land) and '0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You m...原创 2019-01-02 14:06:42 · 96 阅读 · 0 评论 -
Leetcode 92.Reverse Linked List II
Question:Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5-&g...原创 2019-01-10 23:15:00 · 96 阅读 · 0 评论 -
Leetcode 14. Longest Common Prefix
QuestionWrite 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 1Input: [“flower”,“flow”,“flight”]Ou...原创 2018-12-31 00:43:09 · 103 阅读 · 0 评论 -
Leetcode 53. Maximum Subarray
Leetcode 53QuestionSolutionNotesQuestionGiven an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.exampleInput: [-2...原创 2018-12-30 22:07:44 · 105 阅读 · 0 评论 -
19. Remove Nth Node From End of List
QuestionGiven a linked list, remove the n-th node from the end of list and return its head.ExampleGiven linked list: 1->2->3->4->5, and n = 2.After removing the second node from the e...原创 2019-01-04 15:20:19 · 77 阅读 · 0 评论 -
Leetcode: 173. Binary Search Tree Iterator
Question:mplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Solution:...原创 2019-01-27 11:35:02 · 147 阅读 · 0 评论 -
LeetCode: 331. Verify Preorder Serialization of a Binary Tree
Question:Given a string of comma separated values, verify whether it is a correct preorder traversal serialization of a binary tree. Find an algorithm without reconstructing the tree.Each comma sepa...原创 2019-01-27 12:43:23 · 101 阅读 · 0 评论 -
Leetcode: 39. Combination Sum
QuestionGiven a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidateswhere the candidate numbers sums to target.The same...原创 2019-05-23 01:36:34 · 114 阅读 · 0 评论 -
Leetcode: 31. Next Permutation
Question:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest p...原创 2019-03-13 12:19:55 · 99 阅读 · 0 评论 -
Leetcode 2sum 3sum 4sum 总结
2 Sum 3 Sum and 4 Sum questions are similar, and the key of solving the problem is using 2 pointer.2 Sum:Question:Given an array of integers that is already sorted in ascending order, find two numb...原创 2019-03-13 09:55:26 · 110 阅读 · 0 评论 -
Leetcode: 16. 3Sum Closest
Question:Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each in...原创 2019-03-12 09:49:07 · 97 阅读 · 0 评论 -
Leecode: 15. Three Sums
Question: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.Solutionclass Solution { p...原创 2019-03-11 10:56:01 · 315 阅读 · 0 评论