N개의 문자열 중 가장 긴 문자열을 출력
나의 풀이
function solution(s) {
let answer;
let max = Number.MIN_SAFE_INTEGER;
for (let x of s) {
if (x.length > max) {
max = x.length;
answer = x;
}
}
return answer;
}
let str = ["teacher", "time", "student", "beautiful", "good"];
console.log(solution(str));
'코딩테스트 문제풀이 > inflearn' 카테고리의 다른 글
[인프런] Node.js / 섹션1 - 기본문제 풀이 / 16. 중복문자제거 (0) | 2023.01.04 |
---|---|
[인프런] Node.js / 섹션1 - 기본문제 풀이 / 15. 가운데 문자 출력 (0) | 2023.01.04 |
[인프런] Node.js / 섹션1 - 기본문제 풀이 / 13. 대소문자 변환 (0) | 2023.01.04 |
[인프런] Node.js / 섹션1 - 기본문제 풀이 / 12. 대문자로 통일 (0) | 2023.01.04 |
[인프런] Node.js / 섹션1 - 기본문제 풀이 / 10. 문자 찾기 (0) | 2023.01.04 |