ν•΄λ²„λ‹ˆ 2023. 12. 6. 18:41
λ°˜μ‘ν˜•

 

 

 

문제

https://school.programmers.co.kr/learn/courses/30/lessons/12981

 

ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€

μ½”λ“œ μ€‘μ‹¬μ˜ 개발자 μ±„μš©. μŠ€νƒ 기반의 ν¬μ§€μ…˜ 맀칭. ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€μ˜ 개발자 λ§žμΆ€ν˜• ν”„λ‘œν•„μ„ λ“±λ‘ν•˜κ³ , λ‚˜μ™€ 기술 ꢁ합이 잘 λ§žλŠ” 기업듀을 맀칭 λ°›μœΌμ„Έμš”.

programmers.co.kr

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

풀이 

import java.util.HashSet;

class Solution {
    public int[] solution(int n, String[] list) {
        int[] answer = new int[2];
         HashSet<String> word = new HashSet<>();
        int index = 0;


        for (int i = 0; i < list.length; i++) {
            if (i > 0 && word.contains(list[i])) {
                index = i;
                System.out.println(list[i]);
                break;
            } else {
                word.add(list[i]);
            }


            if (i < list.length - 1 && list[i].charAt(list[i].length() - 1) != list[i + 1].charAt(0)) {
                index = i + 1;
                break;
            }
        }

                if (index > 0) {
            index += 1; // 9번째

            answer[0] = index % n;
            System.out.println(Math.ceil((double)index/n));
            answer[1] = (int) Math.ceil((double)index/n);

            if (answer[0] == 0) {
                answer[0] = n;
            }
        }

        return answer;
    }
}

 

 

 

 

 

 

μ •λ‹΅

 

 

 

 

λ°˜μ‘ν˜•