๊ด€๋ฆฌ ๋ฉ”๋‰ด

Daehyunii's Dev-blog

๊ฐ€์žฅ ๊ธด ๋ฌธ์ž์—ด(๊ธฐ๋ณธ ๋ฌธ์ œ ํ’€์ด) ๋ณธ๋ฌธ

๐Ÿ“š Language & CS knowledge/Algorithm (๊ธฐ์ดˆ๋ฌธ์ œํ’€์ด)

๊ฐ€์žฅ ๊ธด ๋ฌธ์ž์—ด(๊ธฐ๋ณธ ๋ฌธ์ œ ํ’€์ด)

Daehyunii 2022. 8. 28. 21:54

๋ฌธ์ œ(์ถœ์ฒ˜ : ์ธํ”„๋Ÿฐ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด ๊ฐ•์˜, ์ •๋ณด์˜ฌ๋ฆผํ”ผ์•„๋“œ)

 

N๊ฐœ์˜ ๋ฌธ์ž์—ด์ด ์ž…๋ ฅ๋˜๋ฉด ๊ทธ ์ค‘ ๊ฐ€์žฅ ๊ธด ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.

โ–ฃ ์ž…๋ ฅ์„ค๋ช…
์ฒซ ์ค„์— ์ž์—ฐ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค.(3<=N<=30)
๋‘ ๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 100์„ ๋„˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ฐ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” ์„œ๋กœ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

โ–ฃ ์ถœ๋ ฅ์„ค๋ช…
์ฒซ ์ค„์— ๊ฐ€์žฅ ๊ธด ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•œ๋‹ค.

โ–ฃ ์ž…๋ ฅ์˜ˆ์ œ 1

5
teacher
time

student

beautiful

good

โ–ฃ ์ถœ๋ ฅ์˜ˆ์ œ 1

beautiful

 

 

Tip

1) ๋นˆ ๋ฌธ์ž์—ด์„ ๋‹ด์€ ๋ณ€์ˆ˜๋ฅผ ๋งŒ๋“ ๋‹ค.

2) ๋ฐ˜๋ณต๋ฌธ์„ ํ™œ์šฉํ•ด์„œ ์š”์†Œ๋“ค์„ ๋ฐ˜๋ณต์‹œํ‚ค๊ณ , lengthํ”„๋กœํผํ‹ฐ๋ฅผ ํ™œ์šฉํ•ด์„œ ๋ฐ˜๋ณต๋˜๋Š” ์š”์†Œ์™€ ๋นˆ ๋ฌธ์ž์—ด์— ๋‹ด์€ ์š”์†Œ์˜ ๊ธธ์ด๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๊ฐ€ ๋” ๊ธด ๋ฌธ์ž๋กœ ๊ฐฑ์‹ ์‹œ์ผœ์ฃผ๋Š” ๊ณผ์ •์„ ๋ฐ˜๋ณตํ•œ๋‹ค.

 

๋ฌธ์ œํ’€์ด

//๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ๋‹ต
function solution(...str){
    answer = ''
    for(let x of str){
        if(x.length > answer.length) answer = x;
    }
    return answer;
}        

console.log(solution('teacher','time','student','beautiful','good','pineapplebanana'));