当前位置:网站首页>2022.7.13-----leetcode.735
2022.7.13-----leetcode.735
2022-07-28 03:55:00 【Lu 727】
public int[] asteroidCollision(int[] asteroids) {
Deque<Integer> s=new ArrayDeque<>();
for(int i=0;i<asteroids.length;i++){
if(s.isEmpty())
s.add(asteroids[i]);
else{
int tmp=s.getLast();
if(tmp>0){
if(asteroids[i]>0)// Consistent with the nearest direction
s.add(asteroids[i]);
else{// Inconsistent direction
while(tmp>0&&tmp<-asteroids[i]){
s.pollLast();// Find quality less than i, Planets with different directions
if(s.isEmpty()) break;
tmp=s.getLast();
}
if(tmp==-asteroids[i]) s.pollLast();// Encounter planets with equal mass
else if(tmp<0||s.isEmpty()) s.add(asteroids[i]);
}
}else
s.add(asteroids[i]);// The previous planetary direction is left
}
}
int[] ans=new int[s.size()];
int idx=0;
while(!s.isEmpty()){
ans[idx++]=s.poll();
}
return ans;
}边栏推荐
- Appnium -- app automated test tool
- Interface automation test, complete introduction
- Practical scripts of mangopapa (contents)
- Read Plato farm's eplato and the reason for its high premium
- Tungsten Fabric SDN — BGP as a Service
- Differences among BRD, MRD and PRD
- Prefix-Tuning: Optimizing Continuous Prompts for Generation
- Do you regret doing automated testing?
- Screenshot of deepstream detection results
- Recursion and non recursion are used to calculate the nth Fibonacci number respectively
猜你喜欢

Server memory failure prediction can actually do this!
![[image classification] 2021 MLP mixer nips](/img/fb/ca25da210c8da2b6b55f372a325a6c.png)
[image classification] 2021 MLP mixer nips

Advanced Mathematics (Seventh Edition) Tongji University exercises 3-5 personal solutions

常用的弱网测试工具

简单、好用的性能测试工具推荐

Selenium -- Web automated testing tool

Simple and easy-to-use performance testing tools recommended

ES6 from entry to mastery 07: Deconstruction assignment

Dynamic planning - 63. Different paths II

Implementation of online rental system based on SSM
随机推荐
LabVIEW loads and uses custom symbols in tree control projects
test case management tool
高等数学(第七版)同济大学 习题3-4 个人解答(前8题)
CANopen learning notes
[openvx] VX for basic use of objects_ lut
Advanced Mathematics (Seventh Edition) Tongji University exercises 3-4 personal solutions (the last 8 questions)
Several ways of connecting upper computer and MES
LeetCode_409_最长回文串
CV2. Threshold(), CV2. Findcontours(), CV2. Findcontours image contour processing
一文读懂Plato Farm的ePLATO,以及其高溢价缘由
过滤器、拦截器、监听器
简单、好用的性能测试工具推荐
Msgan is used for pattern search of multiple image synthesis to generate confrontation Network -- to solve the problem of pattern collapse
Leetcode 0140. word splitting II
Greed - 55. Jumping game
数据挖掘-02
Input upload file and echo FileReader and restrict the type of file selection
Dynamic planning - 1049. Weight of the last stone II
numeric_ Limits the range and related attributes of each data type learned
Advanced Mathematics (Seventh Edition) Tongji University exercises 3-6 personal solutions