user-img
ํ•ญํ•ด99 10
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
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด
thumbnail
99ํด๋Ÿฝ ์ฝ”ํ…Œ ์Šคํ„ฐ๋”” 5์ผ์ฐจ TIL + Programmers ๋ฒ ์ŠคํŠธ ์•จ๋ฒ”
1. ๋ฌธ์ œ ์„ค๋ช…๋ฌธ์ œ ๋งํฌ2. ์ ‘๊ทผ ๋ฐฉ์‹KEY WORD: Sorting, HashMap์Œ์•… ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ ๋‹ค. ( ๋ฉค๋ฒ„ ๋ณ€์ˆ˜: ์ž์‹ ์˜ ๊ณ ์œ ๋ฒˆํ˜ธ, ์žฅ๋ฅด, ํ”Œ๋ ˆ์ด ํšŸ์ˆ˜ )์ž…๋ ฅ ๊ฐ’๋“ค์„ ์ „๋ถ€ ์Œ์•… ๊ฐ์ฒด๋กœ ๋ฐ”๊ฟ”์„œ ArrayList์— ์ถ”๊ฐ€ํ•œ๋‹ค.HashMap์„ ๋งŒ๋“ ๋‹ค. Key = ์žฅ๋ฅด , value = ์žฅ๋ฅด์— ํ•ด๋‹นํ•˜๋Š” ๊ณก๋“ค์˜ ํ”Œ๋ ˆ์ด ์ดํ•ฉ2๋ฒˆ์—์„œ ๋งŒ๋“  ArrayList๋ฅผ ์ •๋ ฌํ•œ๋‹ค. ์ •๋ ฌ ๊ธฐ์ค€์€ ๋ฌธ์ œ ๊ทธ๋Œ€๋กœ๋‹ค. -> Comparator๋ฅผ ๋‹จ์ˆœํ™”ํ•œ Lamda ์‹์„ ์ด์šฉํ•ด ๊ตฌํ˜„๋‹ต๋ณ€์šฉ ansList๋ฅผ ๋งŒ๋“ค๊ณ , ๋‹ต๋ณ€์— ์žฅ๋ฅด๋ณ„๋กœ ๋ช‡ ๋ฒˆ ๋“ค์–ด๊ฐ”๋Š”์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” genreAddedCount๋ผ๋Š” HashMap๋„ ํ•˜๋‚˜ ๋” ๋งŒ๋“ ๋‹ค.genreAddedCount๋Š” Key = ์žฅ๋ฅด, value = ์žฅ๋ฅด ๋ณ„๋กœ ๋‹ต๋ณ€ List์— ๋‚˜์˜จ ํšŸ์ˆ˜ ์ด๋‹ค. .get..
2024.07.27
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด