活跃农民
- 积分
- 888
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2016-6-18
- 最后登录
- 1970-1-1
|
- static class Message{
- int id;
- String type;
- public Message(int id, String type){
- this.id = id;
- this.type = type;
- }
- public Message(String type){
- this.type = type;
- }
- }
- public static List<Message> process(List<Message> messageList){
- Stack<Message> stackA = new Stack<>();
- Stack<Message> stackB = new Stack<>();
- Stack<Message> stackC = new Stack<>();
- for(Message message : messageList){
- if(message.type.equals("A")){
- stackA.push(message);
- }
- else if(message.type.equals("B")){
- stackB.push(message);
- }
- else if(message.type.equals("C")){
- stackC.push(message);
- while(!stackA.isEmpty() && !stackC.isEmpty() && stackA.peek().id == stackC.peek().id){
- stackB.pop().id = stackA.peek().id;
- stackA.pop();
- stackC.pop();
- }
- }
- }
- return messageList;
- }
复制代码
是这样吗?测了几个例子没啥问题。。不过好像有点难证明。。 |
|