
LeetCode
ZQYnn~
这个人很神秘,什么都没有写~
展开
-
LeetCode 5.Longest Palindromic Substring
Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" i...原创 2019-10-30 23:01:10 · 143 阅读 · 0 评论 -
LeetCode 1143.Longest Common Subsequence
Longest Common SubsequenceGiven two strings text1 and text2, return the length of their longest common subsequence.A subsequence of a string is a new string generated from the original string with ...原创 2019-10-20 22:42:27 · 202 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray
53. Maximum SubarrayGiven 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],...原创 2019-10-18 12:16:45 · 116 阅读 · 0 评论 -
LeetCode128.Longest Consecutive Sequence
128. Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100...原创 2019-10-18 10:43:47 · 144 阅读 · 0 评论 -
LeetCode 70. Climbing Stairs
Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will...原创 2019-09-14 12:29:31 · 174 阅读 · 0 评论 -
LeetCode 509. Fibonacci Number
Fibonacci NumberThe Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That ...原创 2019-09-14 12:09:41 · 156 阅读 · 0 评论 -
LeetCode 118. Pascal's Triangle
Pascal's TriangleGiven 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:...原创 2019-09-14 11:33:52 · 197 阅读 · 0 评论 -
LeetCode 344.Reverse String
Reverse StringWrite a function that reverses a string. The input string is given as an array of characters char[].Do not allocate extra space for another array, you must do this by modifying the inp...原创 2019-09-14 11:00:54 · 103 阅读 · 0 评论 -
LeetCode 230.Kth Smallest Element in a BST
Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST’s total elements.Ex...原创 2019-09-14 10:48:28 · 153 阅读 · 0 评论 -
LeetCode 279.Perfect Squares
Perfect SquaresGiven 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 = 12Output: 3 Explanation: 12 = 4 +...原创 2019-09-27 11:00:07 · 122 阅读 · 0 评论 -
LeetCode 300.Longest Increasing Subsequence
Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest incre...原创 2019-09-27 11:02:43 · 133 阅读 · 0 评论 -
LeetCode 62.Unique Paths
Unique PathsA 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...原创 2019-09-29 07:49:50 · 215 阅读 · 0 评论 -
LeetCode 63.Unique Paths II
Unique Paths IIA 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...原创 2019-09-29 12:18:19 · 167 阅读 · 0 评论 -
LeetCode 64.Minimum Path Sum
Minimum Path SumGiven 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 ...原创 2019-09-29 12:23:46 · 158 阅读 · 0 评论 -
LeetCode 174.Dungeon Game
Dungeon Game The demons had captured the princess (P) 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) w...原创 2019-10-01 08:32:17 · 244 阅读 · 0 评论 -
LeetCode 156周赛解题
LeetCode 156 周赛解题5205. 独一无二的出现次数给你一个整数数组 arr,请你帮忙统计数组中每个数的出现次数。如果每个数的出现次数都是独一无二的,就返回 true;否则返回 false。示例 1:输入:arr = [1,2,2,1,1,3]输出:true解释:在该数组中,1 出现了 3 次,2 出现了 2 次,3 只出现了 1 次。没有两个数的出现次数相同。示例...原创 2019-10-02 14:35:11 · 267 阅读 · 0 评论 -
LeetCode 98. Validate Binary Search Tree
Validate Binary Search TreeGiven 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 l...原创 2019-09-14 10:43:50 · 94 阅读 · 0 评论 -
LeetCode 104 .Maximum Depth of Binary Tree
Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A ...原创 2019-09-14 10:34:57 · 170 阅读 · 0 评论 -
LeetCode 36. Valid Sudoku
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column must contai...原创 2019-07-17 19:16:59 · 149 阅读 · 0 评论 -
LeetCode 37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.A sudoku solution must satisfy all of the following rules:Each of the digits 1-9 must occur exactly once in each row.Each of the...原创 2019-07-17 23:31:55 · 135 阅读 · 0 评论 -
LeetCode 51. N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each s...原创 2019-07-21 17:53:42 · 157 阅读 · 0 评论 -
LeetCode 101. Symmetric Tree
101. Symmetric TreeGiven 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 /...原创 2019-09-13 12:05:00 · 119 阅读 · 0 评论 -
LeetCode 102. Binary Tree Level Order Traversal
Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,nul...原创 2019-09-13 12:10:00 · 100 阅读 · 0 评论 -
LeetCode 112. Path Sum
Path SumGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note: A leaf is a node with no children....原创 2019-09-13 12:17:36 · 91 阅读 · 0 评论 -
LeetCode 200. Number of Islands
Number of IslandsGiven 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 vertic...原创 2019-09-13 12:31:16 · 196 阅读 · 0 评论 -
LeetCode 199.Binary Tree Right Side View
Binary Tree Right Side ViewGiven a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.Example:Input: [1,2,3,nul...原创 2019-09-13 12:40:08 · 260 阅读 · 0 评论 -
LeetCode 429. N-ary Tree Level Order Traversal
N-ary Tree Level Order TraversalGiven an n-ary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example, given a 3-ary tree:We should ret...原创 2019-09-13 12:45:41 · 194 阅读 · 0 评论 -
LeetCode 513. Find Bottom Left Tree Value
Find Bottom Left Tree ValueGiven a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2:Input: 1 / \ ...原创 2019-09-13 12:53:00 · 170 阅读 · 0 评论 -
LeetCode 515. Find Largest Value in Each Tree Row
Find Largest Value in Each Tree RowExample:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]You need to find the largest value in each row of a b...原创 2019-09-13 14:45:45 · 118 阅读 · 0 评论 -
LeetCode 111. Minimum Depth of Binary Tree
Minimum Depth of Binary TreeGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A ...原创 2019-09-13 15:11:35 · 127 阅读 · 0 评论 -
LeetCode 100. Same Tree
Same TreeGiven 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....原创 2019-09-13 15:18:52 · 123 阅读 · 0 评论 -
LeetCode 257. Binary Tree Paths
Binary Tree PathsGiven a binary tree, return all root-to-leaf paths.Note: A leaf is a node with no children.Example:Input: 1 / \2 3 \ 5Output: ["1->2->5", "1->3"]Expl...原创 2019-09-14 09:14:07 · 109 阅读 · 0 评论 -
LeetCode 110. Balanced Binary Tree
Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the two subtrees of...原创 2019-09-14 09:31:25 · 131 阅读 · 0 评论 -
LeetCode 94.Binary Tree Inorder Traversal
Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes’ values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]Follow up: Recursive...原创 2019-09-14 10:27:44 · 173 阅读 · 0 评论 -
LeetCode 198.House Robber
House RobberYou 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 a...原创 2019-07-24 12:15:18 · 199 阅读 · 0 评论