We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给你两个大小为 n x n 的二进制矩阵 mat 和 target 。现 以 90 度顺时针轮转 矩阵 mat 中的元素 若干次 ,如果能够使 mat 与 target 一致,返回 true ;否则,返回 false 。
示例 1:
输入:mat = [[0,1],[1,0]], target = [[1,0],[0,1]] 输出:true 解释:顺时针轮转 90 度一次可以使 mat 和 target 一致。
示例 2:
输入:mat = [[0,1],[1,1]], target = [[1,0],[0,1]] 输出:false 解释:无法通过轮转矩阵中的元素使 equal 与 target 一致。
示例 3:
输入:mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]] 输出:true 解释:顺时针轮转 90 度两次可以使 mat 和 target 一致。
提示:
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/determine-whether-matrix-can-be-obtained-by-rotation 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
const findRotation = (mat, target) => { let n = mat.length const rotate = (grid) => { for (let i = 0; i < n; i++) { for (let j = 0; j < i; j++) { [grid[i][j], grid[j][i]] = [grid[j][i], grid[i][j]] } } for (let i = 0; i < n; i++) { for (let j = 0; j < n / 2; j++) { [grid[i][j], grid[i][n - j - 1]] = [grid[i][n - j - 1], grid[i][j]] } } } return [0,0,0,0].some(() => { rotate(mat) for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (mat[i][j] !== target[i][j]) return false } } return true }) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给你两个大小为 n x n 的二进制矩阵 mat 和 target 。现 以 90 度顺时针轮转 矩阵 mat 中的元素 若干次 ,如果能够使 mat 与 target 一致,返回 true ;否则,返回 false 。
示例 1:
示例 2:
示例 3:
提示:
The text was updated successfully, but these errors were encountered: