
-Code
class Solution {
public boolean increasingTriplet(int[] nums) {
// 3개의 수만 관리하면 되므로 1번과 2번 변수를 생성
int first = Integer.MAX_VALUE, second = Integer.MAX_VALUE;
for (int num : nums) {
if (first >= num) {
// 현재 첫 숫자보다 작거나 같으면 저장
first = num;
} else if (second >= num) {
// 첫 숫자보다 크고 현재 두번째 수자보다 작으면 저장
second = num;
} else {
// 첫 번째 수와 두번째 수보다 크면 true
return true;
}
}
// 순차적으로 커질 수 있는 값이 없으면 false
return false;
}
}
처음에 if문을 이상하게 다뤄서 틀리고 힌트를 보고 해결했습니다.
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [프로그래머스/Java] n^2 배열 자르기 (0) | 2026.01.01 |
|---|---|
| [LeetCode/Java] String Compression (0) | 2026.01.01 |
| [LeetCode/Java] Reverse Linked List (0) | 2026.01.01 |
| [백준/Java] 27487번 One and Two (0) | 2026.01.01 |
| [LeetCode/Java] Product of Array Except Self (0) | 2025.12.31 |