Skip to content

Commit 844d1cb

Browse files
committed
Update spiral-matrix.cpp
1 parent 2c58589 commit 844d1cb

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

C++/spiral-matrix.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
class Solution {
55
public:
66
vector<int> spiralOrder(vector<vector<int>>& matrix) {
7-
vector<int> result;
7+
vector<int> res;
88
if (matrix.empty()) {
9-
return result;
9+
return res;
1010
}
1111

1212
for (int left = 0, right = matrix[0].size() - 1,
@@ -15,20 +15,20 @@ class Solution {
1515
++left, --right, ++top, --bottom) {
1616

1717
for (int j = left; j <= right; ++j) {
18-
result.emplace_back(matrix[top][j]);
18+
res.emplace_back(matrix[top][j]);
1919
}
2020
for (int i = top + 1; i < bottom; ++i) {
21-
result.emplace_back(matrix[i][right]);
21+
res.emplace_back(matrix[i][right]);
2222
}
2323
for (int j = right; top < bottom && j >= left; --j) {
24-
result.emplace_back(matrix[bottom][j]);
24+
res.emplace_back(matrix[bottom][j]);
2525
}
2626
for (int i = bottom - 1; left < right && i > top; --i) {
27-
result.emplace_back(matrix[i][left]);
27+
res.emplace_back(matrix[i][left]);
2828
}
2929
}
3030

31-
return result;
31+
return res;
3232
}
3333
};
3434

@@ -38,9 +38,9 @@ class Solution2 {
3838
public:
3939
vector<int> spiralOrder(vector<vector<int>>& matrix) {
4040
const int m = matrix.size();
41-
vector<int> ans;
41+
vector<int> res;
4242
if (m == 0) {
43-
return ans;
43+
return res;
4444
}
4545

4646
const int n = matrix.front().size();
@@ -49,7 +49,7 @@ class Solution2 {
4949
for (int i = 0, j = 0, begini = 0, beginj = 0, endi = m,
5050
endj = n, cnt = 0, total = m * n; cnt < total; ++cnt) {
5151

52-
ans.emplace_back(matrix[i][j]);
52+
res.emplace_back(matrix[i][j]);
5353

5454
switch (action) {
5555
case RIGHT:
@@ -84,6 +84,6 @@ class Solution2 {
8484
break;
8585
}
8686
}
87-
return ans;
87+
return res;
8888
}
8989
};

0 commit comments

Comments
 (0)