classSolution { public: vector<int> findDiagonalOrder(vector<vector<int>>& mat){ int x = 0, y = 0; vector<int> res; int row = mat.size(), col = mat[0].size(); bool flag = true; while(true){ cout << x << "," << y << " " << flag << endl; res.push_back(mat[x][y]); if (x == row - 1 && y == col - 1 ) break; elseif(flag) { // flag 为true时向右上角 if(y == col - 1){ x ++; flag = false; } elseif(x == 0) { y ++; flag = false; } else { x --; y ++; } } else { if(x == row - 1) { y ++; flag = true; } elseif (y == 0) { x ++; flag = true; } else { x ++; y --; } } } return res; } };