Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- two pointers
- Method
- hash table
- 구현
- Data Structure
- array
- implement
- sorting
- database
- Matrix
- Class
- greedy
- 코테
- geometry
- Counting
- Binary Tree
- Math
- Tree
- dynamic programming
- 자바
- 파이썬
- java
- Binary Search
- Number Theory
- SQL
- simulation
- Stack
- 코딩테스트
- string
- bit manipulation
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1051. Height Checker 본문
1. Input
1) 학생들이 설 줄의 번호를 담은 int 배열 heights
2. Output
1) 줄 번호 순으로 정렬했을 때, 순서가 잘못 된 학생의 수
3. Constraint
1) 1 <= heights.length <= 100
2) 1 <= heights[i] <= 100
4. Example
Input: heights = [1,1,4,2,1,3] -> Output: 3
설명:
heights: [1,1,4,2,1,3]
expected: [1,1,1,2,3,4]
2, 4, 5번째가 잘못되었으므로 3을 반환한다.
5. Code
1) 첫 코드(2022/06/28)
int[] expected = Arrays.copyOf(heights, heights.length);
Arrays.sort(expected);
int count = 0;
for(int i=0 ; i<heights.length ; i++)
if(expected[i] != heights[i])
count++;
return count;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1089. Duplicate Zeros (0) | 2022.12.20 |
---|---|
[LeetCode/Easy] 1078. Occurrences After Bigram (0) | 2022.12.16 |
[LeetCode/Easy] 1009. Complement of Base 10 Integer (0) | 2022.12.16 |
[LeetCode/Easy] 977. Squares of a Sorted Array (0) | 2022.12.16 |
[LeetCode/Easy] 961. N-Repeated Element in Size 2N Array (0) | 2022.12.16 |