[프로그래머스/Java] Lv.0 배열 원소의 길이

febCho·2024년 4월 16일
0

코딩테스트

목록 보기
174/253
post-thumbnail

문제

문자열 배열 strlist가 매개변수로 주어집니다. strlist 각 원소의 길이를 담은 배열을 retrun하도록 solution 함수를 완성해주세요.

- 제한사항

  • 1 ≤ strlist 원소의 길이 ≤ 100
  • strlist는 알파벳 소문자, 대문자, 특수문자로 구성되어 있습니다.

풀이

class Solution {
    public int[] solution(String[] strlist) {
        int[] answer = new int[strlist.length];
        
        for(int i=0; i<strlist.length; i++){
            answer[i] = strlist[i].length();
        }
        
        return answer;
    }
}

결과

profile
Done is better than perfect.

0개의 댓글