[Programmers] #120585 - 머쓱이보다 키 큰 사람 [Java][C++][Python]
[Programmers] #120585 - 머쓱이보다 키 큰 사람 [Java][C++][Python]
1. 아이디어
array를 순회하며 각 원소가 height보다 크면 카운팅하면 된다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(N)$ | $O(1)$ |
($N$ = array의 길이)
3. 코드
풀이 [Java][C++][Python]
1
2
3
4
5
6
7
8
9
10
class Solution {
public int solution(int[] array, int height) {
int cnt = 0;
for (int x : array) {
if (x > height) cnt++;
}
return cnt;
}
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
int solution(vector<int> array, int height) {
int cnt = 0;
for (int x : array) {
if (x > height) cnt++;
}
return cnt;
}
1
2
def solution(array, height):
return sum(x > height for x in array)
This post is licensed under CC BY 4.0 by the author.