코테 준비/Java [백준] #17608. 막대기 (브론즈 2) - https://www.acmicpc.net/problem/17608 배열 사용 import java.io.*;import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] height = new int[n]; for (int i = 0; i < n; i++) { height[i] = Integer.parseInt(br.readLine()); } int maxHeight = height[n-1]; int num = 1; for (int i = n-2; i >= 0; i--) { if (height[i] > maxHeight) { maxHeight = height[i]; num++; } } System.out.println(num); }} 마지막 막대기는 무조건 보임 스택 사용 import java.io.*;import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); Stack<Integer> stack = new Stack<>(); for (int i = 0; i < n; i++) { int height = Integer.parseInt(br.readLine()); stack.push(height); } int visibleCount = 0; int maxHeight = 0; while (!stack.isEmpty()) { int currentHeight = stack.pop(); if (currentHeight > maxHeight) { maxHeight = currentHeight; visibleCount++; } } System.out.println(visibleCount); }} 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기피할 수 없다면 즐기는 자가 일류 Contents 당신이 좋아할만한 콘텐츠 [백준] #2559. 수열 (실버 3) 2024.06.09 [백준] #11659. 구간 합 구하기4 (실버 3) 2024.06.06 [백준] #2167. 2차원 배열의 합 (실버 5) 2024.06.05 [백준] #11441. 합 구하기 (실버 3) 2024.06.05 댓글 0 + 이전 댓글 더보기