This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On an N x N grid, each square grid[i][j] represents the elevation at that point (i,j). | |
Now rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to | |
another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. | |
You can swim infinite distance in zero time. Of course, you must stay within the boundaries of the grid during your swim. | |
You start at the top left square (0, 0). What is the least time until you can reach the bottom right square (N-1, N-1)? | |
Example 1: | |
Input: [[0,2],[1,3]] | |
Output: 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0. | |
A move consists of choosing 0 and a 4-directionally adjacent number and swapping it. | |
The state of the board is solved if and only if the board is [[1,2,3],[4,5,0]]. | |
Given a puzzle board, return the least number of moves required so that the state of the board is solved. | |
If it is impossible for the state of the board to be solved, return -1. | |
Examples: | |
Input: board = [[1,2,3],[4,0,5]] | |
Output: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other. | |
Example: | |
Input: start = "RXXLRXRXL", end = "XRLXXRRLX" | |
Output: True | |
Explanation: | |
We can transform start to end following these steps: | |
RXXLRXRXL -> | |
XRXLRXRXL -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Given a Binary Search Tree (BST) with root node root, and a target value V, split the tree into two subtrees where one subtree | |
has nodes that are all smaller or equal to the target value, while the other subtree has all nodes that are greater than the target value. It's not necessarily the case that the tree contains a node with value V. | |
Additionally, most of the structure of the original tree should remain. Formally, for any child C with parent P in the original | |
tree, if they are both in the same subtree after the split, then node C should still have the parent P. | |
You should output the root TreeNode of both subtrees after splitting, in any order. | |
Example 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, | |
and each occurrence of 1 with 10. | |
Given row N and index K, return the K-th indexed symbol in row N. (The values of K are 1-indexed.) (1 indexed).*/ | |
/* This is a medium problem in the Leetcode website. At first, since the next row is closely related to the former row, I generate | |
the next row in a recursive method. And definitely it is subject to Time Limit Exceed. And then I change recursive method with the | |
following code, but it is still Time Limit Exceed. I check the other people code, and discover they just simple observe the feature | |
of the output, and it turns out that the answer is just related to the value of K. I will list the one line Java code here, and let | |
us apprepriate the importance of observation in coding.*/ |