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 |
Tags
- 2870번 수학숙제 c++
- Lv.3
- 17070번
- 백준 c++ 2468번
- Beakjoon
- 2870번 수학숙제
- 백준 1103번 c++
- 백준 c++ 2870번
- Lv2
- 백준 1103번
- 프로그래머스
- 플레이어 이동
- c++
- 코딩테스트
- Unity
- 백준 1103번 게임
- dfs
- 백준
- Algorithm
- 유니티
- 백준 17070번
- 백준 17070번 c++
- 오브젝트 풀링
- 수학숙제
- 코테
- 2870번
- 2468 c++
- 백준 2870번
- C#
- 2870번 c++
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 뒤에 있는 큰 수 찾기 본문
https://school.programmers.co.kr/learn/courses/30/lessons/154539
1. 정답코드 및 핵심 아이디어, 유의사항
- 마지막 인덱스 -> 0번 인덱스 방향으로 검사
1. 초기 값 세팅 : int형 변수 num에 -1을 두고 시작
2. 맨 끝 인덱스부터 순서대로 스택에 담으면서 검사
- Stack<T> https://godgjwnsgur7.tistory.com/46
using System;
using System.Collections.Generic;
public class Solution
{
public int[] solution(int[] numbers)
{
int[] answer = new int[] { };
List<int> list = new List<int>(); // 뒤집힌 answerList
Stack<int> stack = new Stack<int>(); // 지나 온 숫자스택
// 초기 값 세팅
stack.Push(numbers[numbers.Length - 1]);
list.Add(-1);
// 맨 끝 인덱스부터 순서대로 체크 (초기 값 제외)
for (int i = numbers.Length - 2; i >= 0; i--)
{
int num = -1;
while (stack.Count != 0)
{
// 큰 수를 찾음
if (stack.Peek() > numbers[i])
{
num = stack.Peek();
break;
}
else
stack.Pop();
}
list.Add(num);
stack.Push(numbers[i]);
}
answer = list.ToArray();
Array.Reverse(answer);
return answer;
}
}
'CodingTest > Programmers Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 숫자 카드 나누기 (0) | 2023.10.31 |
---|---|
[프로그래머스 C#] Lv.2 시소 짝꿍 (0) | 2023.10.13 |
[프로그래머스 C#] Lv.2 숫자 변환하기 (0) | 2023.09.07 |
[프로그래머스 C#] Lv.2 타겟 넘버 (0) | 2023.09.05 |
[프로그래머스 C#] Lv.2 기능개발 (0) | 2023.09.03 |