当前位置:网站首页>剑指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();
}
}
边栏推荐
- 【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
- 可点击也可直接复制指定内容js
- docker安装postgresSQL和设置自定义数据目录
- SQL statement to range query time field
- Kubernetes加入集群的TOKEN值过期
- sql语句之多表查询
- MySQL8--Windows下使用压缩包安装的方法
- Summary of MySQL common interview questions (recommended collection!!!)
- Paginate the list collection and display the data on the page
- 【MQ我可以讲一个小时】
猜你喜欢
Temporal客户端模型
Unity mobile game performance optimization series: performance tuning for the CPU side
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
剑指offer专项突击版 ---第 5 天
pycharm专业版使用
MYSQL下载及安装完整教程
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
MYSQL一站式学习,看完即学完
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
MySQL optimization slow log query
随机推荐
质量小议12 -- 以测代评
Minio upload file ssl certificate is not trusted
MySQL常见面试题汇总(建议收藏!!!)
DVWA shooting range environment construction
Minesweeper game (written in c language)
About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
mysql5.7.35安装配置教程【超级详细安装教程】
一文了解大厂的DDD领域驱动设计
SQL row-column conversion
The monitoring of Doris study notes
pytorch中的一维、二维、三维卷积操作
Simple read operation of EasyExcel
Summary of MySQL common interview questions (recommended collection!!!)
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
DVWA之SQL注入
Go中间件
MySQL优化之慢日志查询
docker安装postgresSQL和设置自定义数据目录
MySQL window function
分布式事务处理方案大 PK!