Contents

ํŽธ์ง€ (with.Java)

   Feb 28, 2024     1 min read

โ€œํŽธ์ง€โ€ ๋ฌธ์ œ์— ๋Œ€ํ•˜์—ฌ ์•Œ์•„๋ณธ ๊ธ€์ž…๋‹ˆ๋‹ค.

์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ๋ฌธ์ œ๋ฅผ ํ’€๋ฉฐ, ํ’€์—ˆ๋˜ ๋ฌธ์ œ์— ๋Œ€ํ•œ ํšŒ๊ณ ์™€ ๋‹ค๋ฅธ ํ’€์ด ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๋ฉฐ, ์•Œ์•„๊ฐ€๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ์— ๋Œ€ํ•ด ๋จผ์ € ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ

๋จธ์“ฑ์ด๋Š” ํ• ๋จธ๋‹ˆ๊ป˜ ์ƒ์‹  ์ถ•ํ•˜ ํŽธ์ง€๋ฅผ ์“ฐ๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

ํ• ๋จธ๋‹ˆ๊ฐ€ ๋ณด์‹œ๊ธฐ ํŽธํ•˜๋„๋ก ๊ธ€์ž ํ•œ ์ž ํ•œ ์ž๋ฅผ ๊ฐ€๋กœ 2cm ํฌ๊ธฐ๋กœ ์ ์œผ๋ ค๊ณ  ํ•˜๋ฉฐ, ํŽธ์ง€๋ฅผ ๊ฐ€๋กœ๋กœ๋งŒ ์ ์„ ๋•Œ, ์ถ•ํ•˜ ๋ฌธ๊ตฌ message๋ฅผ ์ ๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ํŽธ์ง€์ง€์˜ ์ตœ์†Œ ๊ฐ€๋กœ๊ธธ์ด๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ์‚ฌํ•ญ

  • ๊ณต๋ฐฑ๋„ ํ•˜๋‚˜์˜ ๋ฌธ์ž๋กœ ์ทจ๊ธ‰ํ•ฉ๋‹ˆ๋‹ค.
  • 1 โ‰ค message์˜ ๊ธธ์ด โ‰ค 50
  • ํŽธ์ง€์ง€์˜ ์—ฌ๋ฐฑ์€ ์ƒ๊ฐํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • message๋Š” ์˜๋ฌธ ์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž, โ€˜!โ€™, โ€˜~โ€™ ๋˜๋Š” ๊ณต๋ฐฑ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

messageresult
โ€œhappy birthday!โ€30
โ€œI love you~โ€22

๋ฌธ์ œ์— ๋Œ€ํ•œ ๋‚˜์˜ ํ’€์ด

class Solution {
    public int solution(String message) {
        int answer = message.length() * 2;
        return answer;
    }
}

ํ’€์ด ์„ค๋ช…

  • ์ด ๋ฉ”์†Œ๋“œ๋Š” String ํƒ€์ž…์˜ message ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋ฐ›์•„๋“ค์ด๊ณ , message์˜ ๊ธธ์ด์— 2๋ฅผ ๊ณฑํ•œ ๊ฐ’์„ answer ๋ณ€์ˆ˜์— ์ €์žฅํ•œ ๋’ค, answer๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
  • ์ด ์ฝ”๋“œ๋Š” ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ 2๋ฐฐ๋กœ ๋งŒ๋“  ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.