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
- 자바
- Number Theory
- implement
- Tree
- bit manipulation
- greedy
- Matrix
- Counting
- Stack
- SQL
- Binary Tree
- dynamic programming
- two pointers
- 코딩테스트
- hash table
- Math
- Binary Search
- sorting
- string
- java
- array
- 코테
- Class
- Data Structure
- 구현
- Method
- 파이썬
- geometry
- database
- simulation
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 976. Largest Perimeter Triangle 본문
1. Input
1) 정수 배열 nums
2. Output
1) nums의 세 숫자를 변의 길이로 하는 삼각형을 만들었을 때 가장 큰 둘레의 길이를 반환
2) 삼각형을 만들 수 없다면 0을 반환
3. Constraint
1) 3 <= nums.length <= 10^4
2) 1 <= nums[i] <= 10^6
4. Example
Input: nums = [2,1,2] -> Output: 5
Input: nums = [1,2,1,10] -> Output: 0
5. Code
1) 첫 코드(2023/01/02)
import java.util.*;
int answer = 0;
Arrays.sort(nums);
for(int i=0 ; i<nums.length-2 ; i++){
if(nums[i+1]-nums[i]<nums[i+2] && nums[i+2]<nums[i+1]+nums[i]){
if(nums[i]+nums[i+1]+nums[i+2]>answer)
answer = nums[i]+nums[i+1]+nums[i+2];
}
}
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1720. Decode XORed Array (0) | 2023.01.02 |
---|---|
[LeetCode/Easy] 1716. Calculate Money in Leetcode Bank (0) | 2023.01.02 |
[LeetCode/Easy] 1704. Determine if String Halves Are Alike (0) | 2023.01.02 |
[LeetCode/Easy] 1688. Count of Matches in Tournament (0) | 2023.01.02 |
[LeetCode/Easy] 1684. Count the Number of Consistent Strings (0) | 2023.01.02 |