DFS
Data Structures & Algorithms · 17 notes
- Next Permutationhistorical
Implement a function that obtains the next permutation. The algorithm must rearrange the given sequence of numbers into the next lexicographically greater permutation.
- Subsetshistorical
Given an integer array nums whose elements are all distinct, return all possible subsets (the power set).
- Unique Pathshistorical
A robot starts at the top-left corner of an m × n grid and can move only down or right. Count the paths to the bottom-right corner.
- Number of Islandshistorical
Given a 2D grid consisting of '1' (land) and '0' (water), calculate the number of islands in the grid.
- Maximal Squarehistorical
In a 2D matrix consisting of '0' and '1', find the largest square containing only '1' and return its area.
- Partition Equal Subset Sumhistorical
Given a non-empty array containing only positive integers, determine whether the array can be partitioned into two subsets whose sums are equal.
- Perfect Squareshistorical
Given a positive integer n, find several perfect-square numbers (such as 1, 4, 9, 16, ...) whose sum equals n. You need to minimize the number of perfect squares used.
- Target Sumhistorical
Assign a plus or minus sign to each number in a nonnegative integer array and count the assignments whose sum equals the target S.
- Combination Sumhistorical
Given an array candidates containing no duplicate elements and a target number target, find all combinations of numbers in candidates whose sum equals target.
- Coin Changehistorical
Given coins of different denominations and a total amount, write a function to compute the minimum number of coins needed to make up that amount. If no combination of coins can make up the amount, return -1.
- Burst Balloonshistorical
Each balloon carries a number, and bursting it earns points based on its neighbors. Choose a bursting order that maximizes the total score.
- House Robberhistorical
You are a professional robber planning to rob houses along a street. Each house contains some cash. The only constraint is that adjacent houses have connected security systems, and the alarm will automatically trigger if two adjacent houses are broken into on the same night.
- Best Time to Buy and Sell Stock with Cooldownhistorical
Given daily stock prices, find the maximum trading profit when selling a stock requires a one-day cooldown before buying again.
- Minimum Path Sumhistorical
Given an m x n grid of non-negative integers, find a path from the top-left corner to the bottom-right corner such that the sum of the numbers along the path is minimized.
- Longest Increasing Subsequencehistorical
Given an integer array nums, find the length of the longest strictly increasing subsequence.
- Jump Gamehistorical
Each element of a nonnegative integer array gives the maximum jump length from that position. Determine whether the last position is reachable.