当前位置:网站首页>剑指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();
}
}
边栏推荐
- Apache DButils使用注意事项--with modifiers “public“
- Linux系统安装mysql(rpm方式安装)
- MySQL事务(transaction) (有这篇就足够了..)
- Refinement of the four major collection frameworks: Summary of List core knowledge
- MySQL-如何分库分表?一看就懂
- Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
- The interviewer asked me TCP three handshake and four wave, I really
- C语言如何分辨大小端
- Lock wait timeout exceeded解决方案
- Shell重油常压塔模拟仿真与控制
猜你喜欢
随机推荐
分布式事务处理方案大 PK!
Summary of MySQL common interview questions (recommended collection!!!)
sql语句之多表查询
On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
MySQL事务(transaction) (有这篇就足够了..)
datagrip带参sql查询
Unity mobile game performance optimization series: performance tuning for the CPU side
面试官,不要再问我三次握手和四次挥手
Flink sink redis 写入Redis
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
Kubernetes 证书可用年限修改
C语言指针详解
mysql uses on duplicate key update to update data in batches
110 MySQL interview questions and answers (continuously updated)
Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
MYSQL下载及安装完整教程
运用flask框架发送短信验证码的流程及具体代码
目标检测学习笔记
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
TOGAF之架构标准规范(一)