ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฌธ์ œ ์„ค๋ช…

์ˆ˜๋งŽ์€ ๋งˆ๋ผํ†ค ์„ ์ˆ˜๋“ค์ด ๋งˆ๋ผํ†ค์— ์ฐธ์—ฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋‹จ ํ•œ ๋ช…์˜ ์„ ์ˆ˜๋ฅผ ์ œ์™ธํ•˜๊ณ ๋Š” ๋ชจ๋“  ์„ ์ˆ˜๊ฐ€ ๋งˆ๋ผํ†ค์„ ์™„์ฃผํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๋งˆ๋ผํ†ค์— ์ฐธ์—ฌํ•œ ์„ ์ˆ˜๋“ค์˜ ์ด๋ฆ„์ด ๋‹ด๊ธด ๋ฐฐ์—ด participant์™€ ์™„์ฃผํ•œ ์„ ์ˆ˜๋“ค์˜ ์ด๋ฆ„์ด ๋‹ด๊ธด ๋ฐฐ์—ด completion์ด ์ฃผ์–ด์งˆ ๋•Œ, ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜์˜ ์ด๋ฆ„์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ์‚ฌํ•ญ

  • ๋งˆ๋ผํ†ค ๊ฒฝ๊ธฐ์— ์ฐธ์—ฌํ•œ ์„ ์ˆ˜์˜ ์ˆ˜๋Š” 1๋ช… ์ด์ƒ 100,000๋ช… ์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • completion์˜ ๊ธธ์ด๋Š” participant์˜ ๊ธธ์ด๋ณด๋‹ค 1 ์ž‘์Šต๋‹ˆ๋‹ค.
  • ์ฐธ๊ฐ€์ž์˜ ์ด๋ฆ„์€ 1๊ฐœ ์ด์ƒ 20๊ฐœ ์ดํ•˜์˜ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ฐธ๊ฐ€์ž ์ค‘์—๋Š” ๋™๋ช…์ด์ธ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ

participantcompletionreturn

["leo", "kiki", "eden"] ["eden", "kiki"] "leo"
["marina", "josipa", "nikola", "vinko", "filipa"] ["josipa", "filipa", "marina", "nikola"] "vinko"
["mislav", "stanko", "mislav", "ana"] ["stanko", "ana", "mislav"] "mislav"

์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

์˜ˆ์ œ #1
"leo"๋Š” ์ฐธ์—ฌ์ž ๋ช…๋‹จ์—๋Š” ์žˆ์ง€๋งŒ, ์™„์ฃผ์ž ๋ช…๋‹จ์—๋Š” ์—†๊ธฐ ๋•Œ๋ฌธ์— ์™„์ฃผํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ #2
"vinko"๋Š” ์ฐธ์—ฌ์ž ๋ช…๋‹จ์—๋Š” ์žˆ์ง€๋งŒ, ์™„์ฃผ์ž ๋ช…๋‹จ์—๋Š” ์—†๊ธฐ ๋•Œ๋ฌธ์— ์™„์ฃผํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ #3
"mislav"๋Š” ์ฐธ์—ฌ์ž ๋ช…๋‹จ์—๋Š” ๋‘ ๋ช…์ด ์žˆ์ง€๋งŒ, ์™„์ฃผ์ž ๋ช…๋‹จ์—๋Š” ํ•œ ๋ช…๋ฐ–์— ์—†๊ธฐ ๋•Œ๋ฌธ์— ํ•œ๋ช…์€ ์™„์ฃผํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.

 

 

[ํ’€์ด]

public String solution(String[] participant, String[] completion) {

    HashMap<String, Integer> hashMap = new HashMap<String, Integer>();

    for (String s : participant) {
      if(hashMap.containsKey(s)) {
      	hashMap.put(s,hashMap.get(s).intValue()+1);
      } else {
      	hashMap.put(s, 1);
      }
    }

    for (String s : completion) {
      if(hashMap.get(s) > 0) {
        hashMap.put(s, hashMap.get(s).intValue()-1);
      }
    }

    String answer = "";
    for (Map.Entry<String, Integer> stringIntegerEntry : hashMap.entrySet()) {
      if(stringIntegerEntry.getValue().equals(1)) {
        answer = stringIntegerEntry.getKey();
      }
    }
    return answer;
}

 

๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
๊ธ€ ๋ณด๊ด€ํ•จ