medium
62. Unique Paths
#Problem There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or …
57. Insert Interval
#Problem You are given an array of non-overlapping intervals intervals where intervals[i] = [startᵢ, endᵢ] represent the start and the end of the iᵗʰ interval and intervals is sorted in ascending order by startᵢ. You are also given an …
56. Merge Intervals
#Problem Given an array of intervals where intervals[i] = [startᵢ, endᵢ], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. …
55. Jump Game
#Problem You are given an integer array nums. You are initially positioned at the array’s first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false …
54. Spiral Matrix
#Problem Given an m x n matrix, return all elements of the matrix in spiral order. https://leetcode.com/problems/spiral-matrix/ Example 1: case1Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4,5] Example 2: case2Input: …
435. Non-overlapping Intervals
#Problem Given an array of intervals intervals where intervals[i] = [startᵢ, endᵢ], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Note that intervals which only touch at a point …
49. Group Anagrams
#Problem Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, using all the original letters …
48. Rotate Image
#Problem You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D …
300. Longest Increasing Subsequence
#Problem Given an integer array nums, return the length of the longest strictly increasing subsequence. A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the …
825. Friends Of Appropriate Ages
#Problem There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the iᵗʰ person. A Person x will not send a friend request to a person y (x != y) if any of the following conditions is …
424. Longest Repeating Character Replacement
#Problem You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times. Return the length of the longest …
3240. Minimum Number of Flips to Make Binary Grid Palindromic II
#Problem You are given an m x n binary matrix grid. A row or column is considered palindromic if its values read the same forward and backward. You can flip any number of cells in grid from 0 to 1, or from 1 to 0. Return the minimum number …
417. Pacific Atlantic Water Flow
#Problem There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island’s left and top edges, and the Atlantic Ocean touches the island’s right and bottom edges. The island …
33. Search in Rotated Sorted Array
#Problem There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the resulting array is …
153. Find Minimum in Rotated Sorted Array
#Problem Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: [4,5,6,7,0,1,2] if it was rotated 4 times. [0,1,2,4,5,6,7] if it was rotated 7 …
3239. Minimum Number of Flips to Make Binary Grid Palindromic I
#Problem You are given an m x n binary matrix grid. A row or column is considered palindromic if its values read the same forward and backward. You can flip any number of cells in grid from 0 to 1, or from 1 to 0. Return the minimum number …
152. Maximum Product Subarray
#Problem Given an integer array nums, find a subarray that has the largest product, and return the product. A subarray is a contiguous non-empty sequence of elements within an array. The test cases are generated so that the answer will fit …
19. Remove Nth Node From End of List
#Problem Given the head of a linked list, remove the nᵗʰ node from the end of the list and return its head. https://leetcode.com/problems/remove-nth-node-from-end-of-list/ Example 1: case1Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] …
143. Reorder List
#Problem You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln - 1 → Ln Reorder the list to be on the following form: L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → … You may not modify the values in the …
3249. Count the Number of Good Nodes
#Problem There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [aᵢ, bᵢ] indicates that there is an edge between nodes aᵢ and bᵢ in …
139. Word Break
#Problem Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may be reused multiple times in the …
11. Container With Most Water
#Problem You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that …
647. Palindromic Substrings
#Problem Given a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring is a contiguous sequence of characters within the string. …
133. Clone Graph
#Problem Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors. c++ 复制 class Node { public int val; …
5. Longest Palindromic Substring
#Problem Given a string s, return the longest palindromic substring in s. A string is palindromic if it reads the same forward and backward. A substring is a contiguous non-empty sequence of characters within a string. …
540. Single Element in a Sorted Array
#Problem You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Return the single element that appears only once. Your solution must run in …
3. Longest Substring Without Repeating Characters
#Problem Given a string s, find the length of the longest substring without repeating characters. A substring is a contiguous non-empty sequence of characters within a string. …
128. Longest Consecutive Sequence
#Problem Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. https://leetcode.com/problems/longest-consecutive-sequence/ Example 1: …