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
- Math
- Stack
- Counting
- 코테
- Matrix
- simulation
- bit manipulation
- 구현
- SQL
- database
- dynamic programming
- Binary Tree
- sorting
- Method
- Tree
- Class
- string
- hash table
- array
- implement
- Number Theory
- java
- greedy
- geometry
- Binary Search
- Data Structure
- 자바
- 파이썬
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1491. Average Salary Excluding the Minimum and Maximum Salary 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 1491. Average Salary Excluding the Minimum and Maximum Salary
무지맘 2022. 12. 26. 13:081. Input
1) 중복 요소가 없는 int 배열 salary
- i번째 요소는 i번째 직원이 받는 월급이다.
2. Output
1) 최저 월급과 최고 월급을 뺀 나머지 월급의 평균을 담은 double 변수
2) 정답 확인때는 소수점 아래 5번째 숫자까지 확인
3. Constraint
1) 3 <= salary.length <= 100
2) 1000 <= salary[i] <= 10^6
4. Example
Input: salary = [4000,3000,1000,2000] -> Output: 2500.00000
설명: 최저인 1000과 최고인 4000을 뺀 나머지를 더하면 3000 + 2000 = 5000이 되고, 2개를 더했으므로 2로 나누면 2500.00000이 된다.
5. Code
1) 첫 코드(2022/07/06)
import java.util.*;
Arrays.sort(salary);
if(salary.length==3)
return salary[1];
double sum = 0;
for(int i=1 ; i<salary.length-1 ; i++)
sum += salary[i];
return sum/(salary.length-2);
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Medium] 28. Find the Index of the First Occurrence in a String (0) | 2022.12.26 |
---|---|
[LeetCode/Medium] 215. Kth Largest Element in an Array (0) | 2022.12.26 |
[LeetCode/Easy] 1486. XOR Operation in an Array (0) | 2022.12.26 |
[LeetCode/Easy] 1480. Running Sum of 1d Array (0) | 2022.12.26 |
[LeetCode/Easy] 1475. Final Prices With a Special Discount in a Shop (0) | 2022.12.26 |