fucking-algorithm icon indicating copy to clipboard operation
fucking-algorithm copied to clipboard

[bug][{C++}] {rotate-image/}

Open GT-l opened this issue 2 years ago • 1 comments

请在提交 bug 之前先搜索

  • [X] 我已经搜索过 issues,没有发现相同的 bug。

出错的题目链接

https://leetcode.cn/problems/rotate-image/

报错信息

在c++代码中最后那个翻转一维数组没用,去掉也可以正确编译通过

你是否愿意提交 PR 修复这个 bug?

  • [X] 我愿意!

GT-l avatar Jul 06 '23 01:07 GT-l

class Solution { public: void rotate(vector<vector>& matrix) { int n = matrix.size(); // 先沿对角线反转二维矩阵 for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { swap(matrix[i][j], matrix[j][i]); } } // 然后反转二维矩阵的每一行 for (auto& row : matrix) { reverse(row.begin(), row.end()); } } };

GT-l avatar Jul 06 '23 01:07 GT-l