Skip to content

Commit 5c64b01

Browse files
authored
Create 1944. Number of Visible People in a Queue
1 parent 6f0d6cd commit 5c64b01

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @param {number[]} heights
3+
* @return {number[]}
4+
*/
5+
var canSeePersonsCount = function(heights) {
6+
// 볼 수 있는 조건
7+
// - 바로 오른쪽
8+
// - i j 사이 더 작은 사람
9+
// 시간 복잡도 O(n^2) => TLE
10+
11+
let see = [];
12+
13+
for (let i = 0; i < heights.length; i++){
14+
let count = 0;
15+
let maxHeight = 0;
16+
17+
for (let j = i+1; j<heights.length; j++){
18+
if (Math.min(heights[i], heights[j]) > maxHeight){
19+
count++;
20+
}
21+
22+
maxHeight = Math.max(maxHeight, heights[j]);
23+
}
24+
25+
see.push(count);
26+
}
27+
28+
return see;
29+
};

0 commit comments

Comments
 (0)