![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
万里归来少年心
这个作者很懒,什么都没留下…
展开
-
875. Koko Eating Bananas
Koko loves to eat bananas. There areNpiles of bananas, thei-thpile haspiles[i]bananas. The guards have gone and will come back inHhours.Koko can decide her bananas-per-hour eating speed of...原创 2020-02-19 20:48:30 · 270 阅读 · 0 评论 -
37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Asudoku solution must satisfyall ofthe following rules:Each of the digits1-9must occur exactlyonce in each row. Each of t...原创 2020-02-17 21:39:22 · 290 阅读 · 0 评论 -
36. Valid Sudoku
Determine if a9x9 Sudoku boardis valid.Only the filled cells need to be validatedaccording to the following rules:Each rowmust contain thedigits1-9without repetition. Each column must conta...原创 2020-02-17 20:47:00 · 347 阅读 · 0 评论 -
208. Implement Trie (Prefix Tree)
Implement a trie withinsert,search, andstartsWithmethods.Example:Trie trie = new Trie();trie.insert("apple");trie.search("apple"); // returns truetrie.search("app"); // returns fals...原创 2020-02-16 18:09:48 · 184 阅读 · 0 评论 -
52. N-Queens II
Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return the number ofdistinct solutions to then-queens puzz...原创 2020-02-16 16:24:36 · 225 阅读 · 0 评论 -
51. N-Queens
Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Each ...原创 2020-02-16 15:49:51 · 174 阅读 · 0 评论 -
126. Word Ladder II
Given two words (beginWordandendWord), and a dictionary's word list, find all shortest transformation sequence(s) frombeginWordtoendWord, such that:Only one letter can be changed at a time Eac...原创 2020-02-11 23:49:32 · 369 阅读 · 0 评论 -
127. Word Ladder
Given two words (beginWordandendWord), and a dictionary's word list, find the length of shortest transformation sequence frombeginWordtoendWord, such that:Only one letter can be changed at a ti...原创 2020-02-11 21:12:18 · 263 阅读 · 0 评论 -
146. LRU Cache
Design and implement a data structure forLeast Recently Used (LRU) cache. It should support the following operations:getandput.get(key)- Get the value (will always be positive) of the key if th...原创 2020-02-04 14:57:49 · 770 阅读 · 0 评论 -
最长公共连续子串
给出两个字符串(可能包含空格),找出其中最长的公共连续子串,输出其长度。输入描述: 输入为两行字符串(可能包含空格),长度均小于等于50.输出描述: 输出为一个整数,表示最长公共连续子串的长度。示例1输入abcdeabgde输出2方法一: 输入的两个字符串为s1, s2。申请一个二维数组num[row][col],行数ro...原创 2020-02-04 13:29:06 · 894 阅读 · 0 评论 -
225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. empty() -- Return ...原创 2020-02-03 20:24:24 · 334 阅读 · 0 评论 -
232. Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. em...原创 2020-02-03 19:53:45 · 386 阅读 · 0 评论 -
152. Maximum Product Subarray
Given an integer arraynums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation:[2,3] h...原创 2020-02-02 22:22:46 · 477 阅读 · 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...原创 2020-02-02 19:10:02 · 396 阅读 · 0 评论 -
236. 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 thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p...原创 2020-02-01 15:12:20 · 520 阅读 · 0 评论 -
235. Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined between ...原创 2020-02-01 13:12:07 · 417 阅读 · 0 评论 -
98. 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 contains only nodes with keysless thanthe node's key. The ...原创 2020-01-31 19:51:37 · 462 阅读 · 0 评论 -
242. Valid Anagram
Given two stringssandt, write a function to determine iftis an anagram ofs.Example 1:Input: s = "anagram", t = "nagaram"Output: trueExample 2:Input: s = "rat", t = "car"Output: fal...原创 2020-01-31 14:41:28 · 451 阅读 · 0 评论 -
338. Counting Bits
Given a non negative integer numbernum. For every numbersiin the range0 ≤ i ≤ numcalculate the number of 1's in their binary representation and return them as an array.Example 1:Input: 2Out...原创 2020-01-31 13:05:07 · 1582 阅读 · 0 评论 -
231. Power of Two
Given an integer, write a function to determine if it is a power of two.Example 1:Input: 1Output: true Explanation: 20= 1Example 2:Input: 16Output: trueExplanation: 24= 16Example 3:...原创 2020-01-31 12:38:17 · 410 阅读 · 0 评论 -
191. Number of 1 Bits
Write a function that takes an unsigned integer and returnthe number of '1'bits it has (also known as theHamming weight).Example 1:Input: 00000000000000000000000000001011Output: 3Explanation...原创 2020-01-31 11:59:35 · 349 阅读 · 0 评论 -
547. Friend Circles
There areNstudents in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is adirectfriend of B, and B is adirectfriend of C, then ...原创 2020-01-21 14:18:09 · 359 阅读 · 0 评论 -
200. Number of Islands
Given 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 may assume...原创 2020-01-21 14:15:17 · 332 阅读 · 0 评论 -
703. Kth Largest Element in a Stream
Design a class to findthekth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.YourKthLargestclass will have a constructor wh...原创 2020-01-21 10:22:15 · 436 阅读 · 0 评论 -
206. 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...原创 2020-01-19 21:41:48 · 375 阅读 · 0 评论 -
69. Sqrt(x)
Implementint sqrt(int x).Compute and return the square root ofx, wherexis guaranteed to be a non-negative integer.Since the return typeis an integer, the decimal digits are truncated and only...原创 2020-01-19 21:40:59 · 355 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2020-01-19 21:41:04 · 325 阅读 · 0 评论 -
50. Pow(x, n)
Implementpow(x,n), which calculatesxraised to the powern(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, ...原创 2020-01-19 21:41:19 · 245 阅读 · 0 评论 -
141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-indexed)in the linked list where tail co...原创 2020-01-19 21:41:34 · 266 阅读 · 0 评论 -
24. Swap Nodes in Pairs
Given alinked list, swap every two adjacent nodes and return its head.You maynotmodify the values in the list's nodes, only nodes itself may be changed.Example:Given 1->2->3->4, you...原创 2020-01-19 21:41:34 · 242 阅读 · 0 评论 -
删数
题目:有一个数组a[N]顺序存放0~N-1,要求每隔两个数删掉一个数,到末尾时循环至开头继续进行,求最后一个被删掉的数的原始下标位置。以8个数(N=7)为例:{0,1,2,3,4,5,6,7},0->1->2(删除)->3->4->5(删除)->6->7->0(删除),如此循环直到最后一个数被删除。 解法:用队列模拟,队首取数,用一...原创 2020-01-14 08:58:10 · 347 阅读 · 0 评论 -
45. Jump Game II
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.Your goal is to...原创 2019-02-01 11:14:29 · 241 阅读 · 0 评论 -
187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Write...原创 2019-01-27 17:57:37 · 319 阅读 · 0 评论 -
113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.Note:A leaf is a node with no children.Example:Given the below binary tree andsum = 22,...原创 2019-01-16 18:00:52 · 188 阅读 · 0 评论 -
452. Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-co...原创 2019-02-01 15:07:03 · 155 阅读 · 0 评论 -
76. Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Example:Input: S = "ADOBECODEBANC", T = "ABC"Output: "BANC"Note:I...原创 2019-01-27 22:27:51 · 153 阅读 · 0 评论 -
371. Sum of Two Integers
Calculate the sum of two integersaandb, but you arenot allowedto use the operator+and-.Example 1:Input: a = 1, b = 2Output: 3Example 2:Input: a = -2, b = 3Output: 1 异或运算(^)是...原创 2019-01-16 23:04:49 · 351 阅读 · 0 评论 -
455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a coo...原创 2019-01-29 21:02:20 · 262 阅读 · 0 评论 -
376. Wiggle Subsequence
A sequence of numbers is called awiggle sequenceif the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either pos...原创 2019-01-29 22:13:06 · 243 阅读 · 0 评论 -
78. Subsets
Given a set ofdistinctintegers,nums, return all possible subsets (the power set).Note:The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[ [3], [1...原创 2019-02-18 09:28:46 · 293 阅读 · 0 评论