Question Leetcode 403: Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.
Given a list of stones’ positions (in units) in sorted ascending order, determine if the frog is able to cross the river by landing on the last stone.
Question Leetcode 1036: Escape a Large Maze
In a 1 million by 1 million grid, the coordinates of each grid square are (x, y) with 0 <= x, y < 10^6.
We start at the source square and want to reach the target square. Each move, we can walk to a 4-directionally adjacent square in the grid that isn’t in the given list of blocked squares.
Return true if and only if it is possible to reach the target square through a sequence of moves.
Question Leetcode 1035: Uncrossed Lines
We write the integers of A and B (in the order they are given) on two separate horizontal lines.
Now, we may draw a straight line connecting two numbers A[i] and B[j] as long as A[i] == B[j], and the line we draw does not intersect any other connecting (non-horizontal) line.
Return the maximum number of connecting lines we can draw in this way.
Question Leetcode 1034: Coloring A Border
Given 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 any of the 4 directions.
The border of a connected component is all the squares in the connected component that are either 4-directionally adjacent to a square not in the component, or on the boundary of the grid (the first or last row or column).
今天我们讲解一种算法思想。这种方法一般使用在需要把整个数组分成2份的情况,求这两份组成的是最大、最小、和最大之类的。下面我们来看三道由易到难的题目。
Question Leetcode 238: Product of Array Except Self
Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].
Examples Input: [1,2,3,4] Output: [24,12,8,6] Follow up: Please solve it without division and in O(n). Could you solve it with constant space complexity? (The output array does not count as extra space for the purpose of space complexity analysis.