leetcode
ALLENYYE
这个作者很懒,什么都没留下…
展开
-
138. 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.Return a deep copy of the list.Example 1:Input:{"$id":"1","next...原创 2019-11-20 03:43:04 · 163 阅读 · 0 评论 -
692. Top K Frequent Words
Given a non-empty list of words, return the k most frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the low...原创 2019-11-20 02:27:08 · 162 阅读 · 0 评论 -
88. 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 that n...原创 2019-11-20 01:54:10 · 146 阅读 · 0 评论 -
617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree....原创 2019-11-11 16:29:38 · 124 阅读 · 0 评论 -
973. K Closest Points to Origin
We have a list of points on the plane. Find the K closest points to the origin (0, 0).(Here, the distance between two points on a plane is the Euclidean distance.)You may return the answer in any o...原创 2019-11-04 05:45:32 · 93 阅读 · 0 评论 -
819. Most Common Word
Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn’t banned, and that the answer...原创 2019-11-04 04:16:38 · 110 阅读 · 0 评论 -
179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: "210"Example 2:Input: [3,30,34,5,9]Output: "9534330"Note: The result ...原创 2019-11-03 12:12:23 · 95 阅读 · 0 评论 -
103. Binary Tree Zigzag Level Order Traversal
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 binary tree...原创 2019-11-03 05:46:34 · 122 阅读 · 0 评论 -
101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3 B...原创 2019-11-03 05:28:11 · 113 阅读 · 0 评论 -
222. Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Note:Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely fille...原创 2019-11-03 04:49:47 · 98 阅读 · 0 评论 -
1047. Remove All Adjacent Duplicates In String
Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.We repeatedly make duplicate removals on S until we no longer can.Re...原创 2019-11-03 02:22:25 · 122 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at node c1.Example 1:Input: intersect...原创 2019-11-02 15:34:20 · 119 阅读 · 0 评论 -
171. Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28 ...Example 1:Input: "A"...原创 2019-11-02 15:05:13 · 95 阅读 · 0 评论 -
314. Binary Tree Vertical Order Traversal
Given a binary tree, return the vertical order traversal of its nodes’ values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be from left to...原创 2019-11-02 15:03:22 · 118 阅读 · 0 评论 -
215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5Exampl...原创 2019-11-02 13:58:36 · 106 阅读 · 0 评论 -
118. 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.class Solution { public L...原创 2019-11-02 10:54:24 · 126 阅读 · 0 评论 -
120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7]...原创 2019-11-02 09:44:42 · 100 阅读 · 0 评论 -
174. Dungeon Game
The demons had captured the princess § and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially posit...原创 2019-11-02 09:25:10 · 152 阅读 · 0 评论 -
64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at an...原创 2019-11-02 08:54:13 · 152 阅读 · 0 评论 -
96. Unique Binary Search Trees
Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST's: 1 3 ...原创 2019-11-02 02:10:17 · 100 阅读 · 0 评论 -
73. Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.Example 1:Input: [ [1,1,1], [1,0,1], [1,1,1]]Output: [ [1,0,1], [0,0,0], [1,0,1]]Follo...原创 2019-11-02 02:06:56 · 88 阅读 · 0 评论 -
264. Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.Example:Input: n = 10 Output: 12 Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12...原创 2019-11-01 07:04:12 · 134 阅读 · 0 评论 -
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 c...原创 2019-11-01 06:43:18 · 81 阅读 · 0 评论 -
1099. Two Sum Less Than K
Given an array A of integers and integer K, return the maximum S such that there exists i < j with A[i] + A[j] = S and S < K. If no i, j exist satisfying this equation, return -1.Example 1:In...原创 2019-11-01 02:53:03 · 220 阅读 · 0 评论 -
213. House Robber II
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is ...原创 2019-11-01 02:29:01 · 128 阅读 · 0 评论 -
198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...原创 2019-11-01 02:00:40 · 92 阅读 · 0 评论 -
69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and only t...原创 2019-10-31 11:25:38 · 86 阅读 · 0 评论 -
263. Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.Example 1:Input: 6Output: trueExplanation: 6 = 2 × 3E...原创 2019-10-31 11:09:21 · 81 阅读 · 0 评论 -
204. 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, they are 2, 3, 5, 7.找素数,每次找到素数的时候,可以把素数的倍数都标记为非...原创 2019-10-31 07:21:49 · 74 阅读 · 0 评论 -
100. Same Tree
Given 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 same value.Example 1:...原创 2019-10-31 06:48:35 · 75 阅读 · 0 评论 -
716. Max Stack
Design a max stack that supports push, pop, top, peekMax and popMax.push(x) – Push element x onto stack.pop() – Remove the element on top of the stack and return it.top() – Get the element on the t...原创 2019-10-31 06:04:37 · 151 阅读 · 0 评论 -
91. 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-empty string containing only digits, determine the tot...原创 2019-10-31 05:34:07 · 77 阅读 · 0 评论 -
132. Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.Example:Input: "aab"Output: 1Explanation...原创 2019-10-31 04:47:25 · 82 阅读 · 0 评论 -
131. Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.Example:Input: "aab"Output:[ ["aa","b"], ["a","a","b"...原创 2019-10-31 04:10:50 · 75 阅读 · 0 评论 -
139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The sa...原创 2019-10-31 04:08:23 · 113 阅读 · 0 评论 -
66. 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 ...原创 2019-10-30 15:23:38 · 76 阅读 · 0 评论 -
347. Top K Frequent Elements
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]Example 2:Input: nums = [1], k = 1Output: [1]Note:You may as...原创 2019-10-30 14:48:01 · 85 阅读 · 0 评论 -
49. Group Anagrams
Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat","tan"], ["bat"]]Note:All inputs will be ...原创 2019-10-30 13:56:31 · 82 阅读 · 0 评论 -
59. Spiral Matrix II
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.Example:Input: 3Output:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]class Solution { pub...原创 2019-10-30 12:27:23 · 85 阅读 · 0 评论 -
211. Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only letters a...原创 2019-10-30 04:27:47 · 96 阅读 · 0 评论