user-img
์ฝ”๋”ฉํ…Œ์ŠคํŠธ์ค€๋น„ 1
thumbnail
99ํด๋Ÿฝ ์ฝ”ํ…Œ ์Šคํ„ฐ๋”” 8์ผ์ฐจ TIL + Programmers ๋‘ ํ์˜ ํ•ฉ ๊ฐ™๊ฒŒ ๋งŒ๋“ค๊ธฐ (java)
1. ๋ฌธ์ œ ์„ค๋ช…๋ฌธ์ œ ๋งํฌ2. ์ ‘๊ทผ ๋ฐฉ์‹KEY WORD: GREEDY๋ฌธ์ œ ์„ค๋ช… ๊ทธ๋Œ€๋กœ Queue ๋‘ ๊ฐœ๋ฅผ ๋งŒ๋“ ๋‹ค.์ดํ•ฉ์ด ํฐ ์ชฝ์˜ queue.peek()์„ poll ํ•ด์„œ ๋‹ค๋ฅธ ์ชฝ ํ์— ์ถ”๊ฐ€ํ•œ๋‹ค.2๋ฒˆ ์ข…๋ฃŒ ํ›„ ๋‘ ํ์˜ ์ดํ•ฉ์ด ๊ฐ™์€์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค.๋งŒ์•ฝ ๊ฐ™์œผ๋ฉด, 2๋ฒˆ์„ ํ–‰ํ•œ ํšŸ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ ๋‘ ํ์˜ ์ด ๊ธธ์ด + 1 ๋งŒํผ ํ•ด๋„ ๋‘ ํ์˜ ํ•ฉ์ด ๊ฐ™์ง€ ์•Š์œผ๋ฉด -1์„ ์ถœ๋ ฅํ•˜๊ณ  ์ข…๋ฃŒ ํ•œ๋‹ค.๋‘ ํ์˜ ์ด ๊ธธ์ด + 1 ๋งŒํผ ๋ฐ˜๋ณตํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋’ค์—์„œ ์„ค๋ช….3. ์ฝ”๋“œ ๋ถ„์„import java.io.*;import java.util.*;class Solution { public int solution(int[] queue1, int[] queue2) { ArrayDeque a = new ArrayDeque()..
2024.07.29
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด