[Programmers] #120854 - 배열 원소의 길이 [Java][C++][Python]
[Programmers] #120854 - 배열 원소의 길이 [Java][C++][Python]
1. 아이디어
각 문자열의 길이를 같은 순서로 모은 배열을 구하는 문제다.
2. 코드
풀이 [Java][C++][Python]
1
2
3
4
5
6
7
8
9
10
class Solution {
public int[] solution(String[] strlist) {
int[] arr = new int[strlist.length];
for (int i = 0; i < strlist.length; i++) {
arr[i] = strlist[i].length();
}
return arr;
}
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
vector<int> solution(vector<string> strlist) {
vector<int> v;
for (string& s : strlist) {
v.push_back(s.length());
}
return v;
}
1
2
def solution(strlist):
return [len(s) for s in strlist]
This post is licensed under CC BY 4.0 by the author.