4
4
class Solution {
5
5
public:
6
6
vector<int > spiralOrder (vector<vector<int >>& matrix) {
7
- vector<int > result ;
7
+ vector<int > res ;
8
8
if (matrix.empty ()) {
9
- return result ;
9
+ return res ;
10
10
}
11
11
12
12
for (int left = 0 , right = matrix[0 ].size () - 1 ,
@@ -15,20 +15,20 @@ class Solution {
15
15
++left, --right, ++top, --bottom) {
16
16
17
17
for (int j = left; j <= right; ++j) {
18
- result .emplace_back (matrix[top][j]);
18
+ res .emplace_back (matrix[top][j]);
19
19
}
20
20
for (int i = top + 1 ; i < bottom; ++i) {
21
- result .emplace_back (matrix[i][right]);
21
+ res .emplace_back (matrix[i][right]);
22
22
}
23
23
for (int j = right; top < bottom && j >= left; --j) {
24
- result .emplace_back (matrix[bottom][j]);
24
+ res .emplace_back (matrix[bottom][j]);
25
25
}
26
26
for (int i = bottom - 1 ; left < right && i > top; --i) {
27
- result .emplace_back (matrix[i][left]);
27
+ res .emplace_back (matrix[i][left]);
28
28
}
29
29
}
30
30
31
- return result ;
31
+ return res ;
32
32
}
33
33
};
34
34
@@ -38,9 +38,9 @@ class Solution2 {
38
38
public:
39
39
vector<int > spiralOrder (vector<vector<int >>& matrix) {
40
40
const int m = matrix.size ();
41
- vector<int > ans ;
41
+ vector<int > res ;
42
42
if (m == 0 ) {
43
- return ans ;
43
+ return res ;
44
44
}
45
45
46
46
const int n = matrix.front ().size ();
@@ -49,7 +49,7 @@ class Solution2 {
49
49
for (int i = 0 , j = 0 , begini = 0 , beginj = 0 , endi = m,
50
50
endj = n, cnt = 0 , total = m * n; cnt < total; ++cnt) {
51
51
52
- ans .emplace_back (matrix[i][j]);
52
+ res .emplace_back (matrix[i][j]);
53
53
54
54
switch (action) {
55
55
case RIGHT:
@@ -84,6 +84,6 @@ class Solution2 {
84
84
break ;
85
85
}
86
86
}
87
- return ans ;
87
+ return res ;
88
88
}
89
89
};
0 commit comments