@@ -114,6 +114,37 @@ class Solution {
114
114
}
115
115
```
116
116
117
+ ### ** JavaScript**
118
+
119
+ ``` js
120
+ /**
121
+ * @param {number[][]} matrix
122
+ * @return {number[]}
123
+ */
124
+ var spiralOrder = function (matrix ) {
125
+ let m = matrix .length ;
126
+ if (m === 0 ) return [];
127
+ let res = [];
128
+ let top = 0 , bottom = m - 1 , left = 0 , right = matrix[0 ].length - 1 ;
129
+ while (left < right && bottom > top) {
130
+ for (let i = left; i < right; i++ ) res .push (matrix[top][i]);
131
+ for (let i = top; i < bottom; i++ ) res .push (matrix[i][right]);
132
+ for (let i = right; i > left; i-- ) res .push (matrix[bottom][i]);
133
+ for (let i = bottom; i > top; i-- ) res .push (matrix[i][left]);
134
+ top++ ;
135
+ bottom-- ;
136
+ left++ ;
137
+ right-- ;
138
+ }
139
+ if (left === right) {
140
+ for (i = top; i <= bottom; i++ ) res .push (matrix[i][left]);
141
+ } else if (top === bottom) {
142
+ for (i = left; i <= right; i++ ) res .push (matrix[top][i]);
143
+ }
144
+ return res;
145
+ };
146
+ ```
147
+
117
148
### ** ...**
118
149
119
150
```
0 commit comments