Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
123 147 741
456 => 258 => 852
789 369 963
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int sz = matrix.size();
for (int i = 0; i < sz; ++i) {
for (int j = i + 1; j < sz; ++j) {
swap(matrix[i][j], matrix[j][i]);
}
reverse(matrix[i].begin(), matrix[i].end());
}
}
};