题解 | #操作序列#

操作序列

http://www.nowcoder.com/practice/b53bda356a494154b6411d80380295f5

你们的方法都好高端,我只想到了用链表的方式来解决这个问题
意外的内存和速度都比较好

import java.util.*;
public class Main {
        public static void main(String[] args){
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            ListNode head=new ListNode(sc.nextInt());
            ListNode foot=head;
            if(n%2==0){
            for(int i=1;i<n;i++){
                ListNode temp=new ListNode(sc.nextInt());
                if(i%2==0){
                    foot.next=temp;
                    foot=temp;
                }else{
                    temp.next=head;
                    head=temp;
                }
            }}else{
                for(int i=1;i<n;i++){
                    ListNode temp=new ListNode(sc.nextInt());
                    if(i%2==1){
                        foot.next=temp;
                        foot=temp;
                    }else{
                        temp.next=head;
                        head=temp;
                    }
                }
            }

            for(int i=0;i<n;i++){
                System.out.print(head.date);
                System.out.print(" ");
                head=head.next;
            }
        }
}
class ListNode{
    public int date;
    public ListNode next;
    ListNode(int da){
        this.date=da;
    }
}
全部评论

相关推荐

湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务