Super Kawaii Cute Cat Kaoani [JAVA][Baekjoon] 2164번 카드2

[JAVA][Baekjoon] 2164번 카드2

2024. 5. 12. 00:38
728x90
SMALL

https://www.acmicpc.net/problem/2164

📌 접근 방식

  • Queue를 이용하면 쉽게 구현할 수 있었다!

 

 

✅ PASS CODE

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String [] args) throws IOException {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        Queue<Integer> queue = new LinkedList<>();

        for(int i = 1; i <= N; i++) {
            queue.add(i);
        }


        while(queue.size() != 1) {
            queue.remove();
            if(queue.size() == 1){
                System.out.println(queue.remove());
                break;
            }
            queue.add(queue.remove());
        }
    }
}

 

 

728x90

 

728x90
LIST

BELATED ARTICLES

more