Publish:

ํƒœ๊ทธ: , , , , ,

์นดํ…Œ๊ณ ๋ฆฌ:

img_3.png

๋ฌธ์ œ

๋ฌธ์ œ ๋งํฌ

img_3.png

์„ค๋ช…

๊ตฌ๋ช…๋ณดํŠธ์˜ ๋ฌด๊ฒŒ ์ œํ•œ์ด ์žˆ๊ณ  ์ตœ๋Œ€ 2๋ช…๊นŒ์ง€๋งŒ ํƒœ์šธ ์ˆ˜ ์žˆ๋‹ค. ๋ฐฐ์—ด์˜ ์‚ฌ๋žŒ์„ ๋ชจ๋‘ ์˜ฎ๊ธฐ๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ตฌ๋ช… ๋ณดํŠธ์˜ ์ˆ˜๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.

ํ’€์ด

  1. ๋จผ์ € ์ž…๋ ฅ๋ฐ›์€ ๋ฐฐ์—ด์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด ์ธ๋ฑ์Šค๋กœ ์ ‘๊ทผํ•˜๊ธฐ ํŽธํ•˜๋„๋ก ๋งŒ๋“ ๋‹ค.
  2. ๊ฐ€์žฅ ๊ฐ€๋ฒผ์šด ์‚ฌ๋žŒ๊ณผ ๊ฐ€์žฅ ๋ฌด๊ฑฐ์šด ์‚ฌ๋žŒ์„ ํƒœ์›Œ๋ณด๊ณ , ๋ฌด๊ฒŒ ์ œํ•œ์— ๊ฑธ๋ฆฌ์ง€ ์•Š์œผ๋ฉด answer ๋ฅผ 1 ์ฆ๊ฐ€ ์‹œํ‚จ๋‹ค.
  3. ๊ทธ๋ฆฌ๊ณ  ๋งจ ์ฒ˜์Œ ์ธ๋ฑ์Šค(๊ฐ€์žฅ ๊ฐ€๋ฒผ์šด ์‚ฌ๋žŒ์˜ ์ธ๋ฑ์Šค)๋ฅผ 1 ์ฆ๊ฐ€์‹œํ‚ค๊ณ  ๊ฐ€์žฅ ์˜ค๋ฅธ์ชฝ(๊ฐ€์žฅ ๋ฌด๊ฑฐ์šด ์‚ฌ๋žŒ์˜ ์ธ๋ฑ์Šค) ๋ฅผ 1 ๊ฐ์†Œ์‹œ์ผœ ๋ฐฐ์—ด์„ ์–‘์ชฝ์—์„œ ํƒ์ƒ‰ํ•˜๋„๋ก ํ•œ๋‹ค. (ํˆฌ ํฌ์ธํ„ฐ)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
  public int solution(int[] people, int limit) {
    int answer = 0;
    Arrays.sort(people);
    int left = 0;
    int right = people.length - 1;

    while (left <= right) {
      if (people[left] + people[right] <= limit) {
        left++;
      }
      answer++;
      right--;
    }
    return answer;
  }
}
๋ฐฉ๋ฌธํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋Œ“๊ธ€,์ง€์ ,ํ”ผ๋“œ๋ฐฑ ์–ธ์ œ๋‚˜ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜Š

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ