当前位置:网站首页>剑指offer基础版 ----- 第25天
剑指offer基础版 ----- 第25天
2022-07-31 05:09:00 【米兰的小红黑】

class Solution {
public int[] spiralOrder(int[][] matrix) {
if(matrix.length == 0){
return new int[0];
}
int[] arr = new int[matrix.length * matrix[0].length];
List<Integer> list= new ArrayList<>();
int left = 0;
int right = matrix[0].length -1;
int high = 0;
int low = matrix.length -1;
while(true){
int a = left;
while(a <= right){
list.add(matrix[high][a++]);
}
if(++high > low){
break;
}
int b = high;
while(b <= low){
list.add(matrix[b++][right]);
}
if(--right < left){
break;
}
int c = right;
while(c >= left){
list.add(matrix[low][c--]);
}
if(--low < high){
break;
}
int d = low;
while(d >= high){
list.add(matrix[d--][left]);
}
if(++left > right){
break;
}
}
int j = 0;
for(int i : list){
arr[j] = i;
j++;
}
return arr;
}
}

class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
Stack<Integer> stack = new Stack<>();
int i = 0;
for(int num : pushed) {
stack.push(num); // num 入栈
while(!stack.isEmpty() && stack.peek() == popped[i]) {
// 循环判断与出栈
stack.pop();
i++;
}
}
return stack.isEmpty();
}
}
边栏推荐
- DVWA靶场环境搭建
- MySQL(更新中)
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
- 关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
- C语言教程(一)-准备
- DVWA shooting range environment construction
- 面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
- Sql解析转换之JSqlParse完整介绍
- Numpy中np.meshgrid的简单用法示例
- Mysql——字符串函数
猜你喜欢
随机推荐
datagrip带参sql查询
DVWA安装教程(懂你的不懂·详细)
.NET-6.WinForm2.NanUI learning and summary
SQL row-column conversion
sql statement - how to query data in another table based on the data in one table
Paginate the list collection and display the data on the page
centos7安装mysql5.7步骤(图解版)
DVWA之SQL注入
Unity mobile game performance optimization series: performance tuning for the CPU side
About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
数据集划分以及交叉验证法
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
pytorch中的一维、二维、三维卷积操作
质量小议12 -- 以测代评
Temporal客户端模型
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
MySQL优化之慢日志查询
Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
可点击也可直接复制指定内容js
Workflow番外篇








