- 博客(114)
- 资源 (1)
- 收藏
- 关注
原创 LeetCode-215 Kth Largest Element in an Array
DescriptionGiven an integer array nums and an integer k, return the kth largest element in the array.Note that it is the kth largest element in the sorted order, not the kth distinct element.Constraints:• 1 <= k <= nums.length <= 104^44• -10
2021-06-04 20:58:45 282
原创 LeetCode-141 Linked List Cycle
DescriptionGiven head, the head of a linked list, determine if the linked list has a cycle in it.There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is
2021-05-28 20:16:14 246
原创 LeetCode-704 Binary Search
DescriptionGiven an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.You must write an algorithm with O(log n) runti
2021-05-25 22:26:07 225
原创 LeetCode-104 Maximum Depth of Binary Tree
DescriptionGiven the root of a binary tree, return its maximum depth.A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Constraints:• The number of nodes in the tree is in the r
2021-05-21 20:35:10 155
原创 LeetCode-744 Find Smallest Letter Greater Than Target
DescriptionGiven a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target.Letters also wrap around. For example, if the target is t
2021-05-18 20:02:43 1268
原创 LeetCode-87 Scramble String
DescriptionWe can scramble a string s to get a string t using the following algorithm:If the length of the string is 1, stop.If the length of the string is > 1, do the following:• Split the string into two non-empty substrings at a random index, i.
2021-04-20 20:43:37 99
原创 LeetCode-945 Minimum Increment to Make Array Unique
DescriptionGiven an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.Return the least number of moves to make every value in A unique.Note:0 <= A.length <= 400000 <= A[i] < 40000ExampleExample 1:Inpu
2021-04-06 10:29:34 78
原创 LeetCode-89 Gray Code
DescriptionThe gray code is a binary numeral system where two successive values differ in only one bit.Given an integer n representing the total number of bits in the code, return any sequence of gray code.A gray code sequence must begin with 0.Constra
2021-04-02 20:21:18 229 2
原创 LeetCode-1377 Frog Position After T Seconds
DescriptionGiven an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly connected. The frog can not jump
2021-03-30 19:00:48 153
原创 LeetCode-98 Validate Binary Search Tree
DescriptionGiven the root of a binary tree, determine if it is a valid binary search tree (BST).A valid BST is defined as follows:• The left subtree of a node contains only nodes with keys less than the node’s key.• The right subtree of a node contains
2021-03-26 19:16:30 146 1
原创 LeetCode-85 Maximal Rectangle
DescriptionGiven a rows x cols binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.Constraints:• rows == matrix.length• cols == matrix[i].length• 0 <= row, cols <= 200• matrix[i][j] is ‘0’ o
2021-03-23 19:29:54 116
原创 LeetCode-90. Subsets II
DescriptionGiven an integer array nums that may contain duplicates, return all possible subsets (the power set).The solution set must not contain duplicate subsets. Return the solution in any order.Constraints:• 1 <= nums.length <= 10• -10 <=
2021-03-19 20:57:14 103
原创 LeetCode-84 Largest Rectangle in Histogram
DescriptionGiven an array of integers heights representing the histogram’s bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.Constraints:• 1 <= heights.length <= 105^55• 0 <= heights[i] <
2021-03-16 21:47:43 147
原创 LeetCode-1482 Minimum Number of Days to Make m Bouquets
DescriptionGiven an integer array bloomDay, an integer m and an integer k.We need to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] an
2021-03-12 21:26:55 128
原创 LeetCode-690 Employee Importance
DescriptionYou are given a data structure of employee information, which includes the employee’s unique id, their importance value and their direct subordinates’ id.For example, employee 1 is the leader of employee 2, and employee 2 is the leader of empl
2021-03-05 21:05:54 92
原创 LeetCode-82 Remove Duplicates from Sorted List II
DescriptionGiven the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.Constraints:• The number of nodes in the list is in the range [0
2021-02-26 22:25:29 96
原创 LeetCode-86 Partition List
DescriptionGiven the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of the two partitions.Constraints:•
2021-02-23 21:38:10 128
原创 LeetCode-81 Search in Rotated Sorted Array II
DescriptionYou are given an integer array nums sorted in ascending order (not necessarily distinct values), and an integer target.Suppose that nums is rotated at some pivot unknown to you beforehand (i.e., [0,1,2,4,4,4,5,6,6,7] might become [4,5,6,6,7,0,
2021-02-02 21:26:50 105
原创 LeetCode-1550 Three Consecutive Odds
DescriptionGiven an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.Constraints:• 1 <= arr.length <= 1000• 1 <= arr[i] <= 1000ExampleExample 1:Input: arr = [2,6,4,1]Output:
2021-01-29 21:13:11 126
原创 LeetCode-80 Remove Duplicates from Sorted Array II
DescriptionGiven a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extra space for another array; you must do this by modifying the input array in-place with O(1) ext
2021-01-26 19:28:06 121
原创 LeetCode-88 Merge Sorted Array
DescriptionGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has a size equal to m + n such that it has en
2021-01-22 21:33:26 93
原创 LeetCode-1314 Matrix Block Sum
DescriptionGiven a m * n matrix mat and an integer K, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for i - K <= r <= i + K, j - K <= c <= j + K, and (r, c) is a valid position in the matrix.Constraints:
2021-01-19 21:22:16 160 1
原创 LeetCode-100 Same Tree
DescriptionGiven the roots of two binary trees p and q, 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.Constraints:• The number of nod
2021-01-15 22:01:29 116
原创 LeetCode-148 Sort List
DescriptionGiven the head of a linked list, return the list after sorting it in ascending order.Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?Constraints:• The number of nodes in the list is in the rang
2021-01-12 21:35:16 70
原创 LeetCode-125 Valid Palindrome
DescriptionGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Constraints:• s consists only of printable ASCII c
2021-01-03 15:25:54 71
原创 LeetCode-136 Single Number
DescriptionGiven a non-empty array of integers nums, every element appears twice except for one. Find that single one.Follow up: Could you implement a solution with a linear runtime complexity and without using extra memory?Constraints:• 1 <= nums.l
2020-12-29 21:32:37 148
原创 LeetCode-424 Longest Repeating Character Replacement
DescriptionGiven a string s that consists of only uppercase English letters, you can perform at most k operations on that string.In one operation, you can choose any character of the string and change it to any other uppercase English character.Find the
2020-11-20 20:08:27 124
原创 LeetCode-885 Spiral Matrix III
DescriptionOn a 2 dimensional grid with R rows and C columns, we start at (r0, c0) facing east.Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the grid is at the last row and column.Now, we walk in a
2020-11-17 20:59:38 89
原创 LeetCode-83 Remove Duplicates from Sorted List
DescriptionGiven a sorted linked list, delete all duplicates such that each element appear only once.ExampleExample 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1->2->3Submissions首先已知链表是有序的,因此只需遍历链表
2020-11-13 22:35:55 134
原创 LeetCode-1248 Count Number of Nice Subarrays
DescriptionGiven an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.Return the number of nice sub-arrays.Constraints:• 1 <= nums.length <= 50000• 1 <= nums[i] <= 10^5• 1 <=
2020-11-10 20:33:15 129
原创 LeetCode-931 Minimum Falling Path Sum
DescriptionGiven a square array of integers A, we want the minimum sum of a falling path through A.A falling path starts at any element in the first row, and chooses one element from each row. The next row’s choice must be in a column that is different
2020-11-06 20:08:17 114
原创 LeetCode-1034 Coloring A Border
DescriptionGiven a 2-dimensional grid of integers, each value in the grid represents the color of the grid square at that location.Two squares belong to the same connected component if and only if they have the same color and are next to each other in an
2020-11-03 21:13:28 111
原创 LeetCode-94 Binary Tree Inorder Traversal
DescriptionGiven the root of a binary tree, return the inorder traversal of its nodes’ values.Constraints:• The number of nodes in the tree is in the range [0, 100].• -100 <= Node.val <= 100Follow up:Recursive solution is trivial, could you do
2020-10-30 22:58:08 157
原创 LeetCode-79 Word Search
DescriptionGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cells, where “adjacent” cells are horizontally or vertically neighboring. The same letter cell may not be used m
2020-10-27 20:35:59 116
原创 LeetCode-78 Subsets
DescriptionGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.ExampleExample:Input: nums = [1,2,3]Output:[[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]S
2020-10-20 20:06:52 86
原创 LeetCode-77 Combinations
DescriptionGiven two integers n and k, return all possible combinations of k numbers out of 1 … n.You may return the answer in any order.Constraints:• 1 <= n <= 20• 1 <= k <= nExampleExample 1:Input: n = 4, k = 2Output:[[2,4],[3,4],
2020-10-16 16:01:05 106
原创 LeetCode-76 Minimum Window Substring
DescriptionGiven 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).Note:• If there is no such window in S that covers all characters in T, return the empty string “”.• If there is such
2020-10-09 21:37:49 76
原创 LeetCode-75 Sort Colors
DescriptionGiven an array nums 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 red, white, and blue.Here, we will use the integers 0, 1, and 2 to represent the co
2020-10-07 15:53:28 125
原创 LeetCode-74 Search a 2D Matrix
DescriptionWrite 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 from left to right.• The first integer of each row is greater than the last integer of the p
2020-09-29 20:40:03 126
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人