LeetCode-Solutions-in-Cpp17

Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.


Project maintained by downdemo Hosted on GitHub Pages — Theme by mattgraham
123    147    741
456 => 258 => 852
789    369    963
class Solution {
 public:
  void rotate(vector<vector<int>>& matrix) {
    int sz = size(matrix);
    for (int i = 0; i < sz; ++i) {
      for (int j = i + 1; j < sz; ++j) {
        swap(matrix[i][j], matrix[j][i]);
      }
      reverse(begin(matrix[i]), end(matrix[i]));
    }
  }
};