Weekly Contest
程式碼:
class Solution { public: vector<int> zigzagTraversal(vector<vector<int>>& grid) { vector<int> results; for (int i = 0; i < grid.size(); i++) { if (i % 2) for (int j = grid[i].size() - 1; j >= 0; j--) { if ((i + j) % 2 == 0) results.push_back(grid[i][j]); } else for (int j = 0; j < grid[i].size(); j++) { if ((i + j) % 2 == 0) results.push_back(grid[i][j]); } } return results; } };
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up