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
- 자바
- hash table
- bit manipulation
- Number Theory
- two pointers
- Stack
- greedy
- sorting
- dynamic programming
- Counting
- simulation
- 파이썬
- 코테
- Class
- Method
- Math
- implement
- Binary Search
- Binary Tree
- java
- Tree
- array
- Matrix
- SQL
- string
- Data Structure
- 코딩테스트
- 구현
- database
- geometry
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1464. Maximum Product of Two Elements in an Array 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 1464. Maximum Product of Two Elements in an Array
무지맘 2022. 12. 25. 22:181. Input
1) int 배열 nums
2. Output
1) (nums[i]-1)*(nums[j]-1)값이 가장 큰 값을 반환
2) 이때 i != j
3. Constraint
1) 2 <= nums.length <= 500
2) 1 <= nums[i] <= 10^3
4. Example
Input: nums = [3,4,5,2] -> Output: 12
설명: 총 6가지 경우가 나오게 된다.
- (3-1) * (4-1) = 6
- (3-1) * (5-1) = 8
- (3-1) * (2-1) = 2
- (4-1) * (5-1) = 12
- (4-1) * (2-1) = 3
- (5-1) * (2-1) = 4
- 따라서 12를 반환한다.
5. Code
1) 첫 코드(2022/06/10)
Arrays.sort(nums);
return ((nums[nums.length-1]-1)*(nums[nums.length-2]-1));