250x250
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
- rigidbody
- 2D슈팅게임
- 플레이어 이동
- Animation State Machine
- joystick
- Object Poling
- 플레이어 방향전환
- Vector3
- Hpbar
- Transform
- 스크롤링
- CSharp #자료구조
- Hp바
- 오브젝트 풀링
- rotation
- 프리팹
- Object Pooling
- 패럴렉스
- Scrooling
- 일시정지
- apk
- raycasting
- LayerMark
- Parallax
- Prefabs
- Blend Type
- raycast
- 유니티
- Ainimation Blending
- Unity
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 뒤에 있는 큰 수 찾기 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/154539
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 정답코드 및 핵심 아이디어, 유의사항
- 마지막 인덱스 -> 0번 인덱스 방향으로 검사
1. 초기 값 세팅 : int형 변수 num에 -1을 두고 시작
2. 맨 끝 인덱스부터 순서대로 스택에 담으면서 검사
- Stack<T> https://godgjwnsgur7.tistory.com/46
[C#] 자료구조 정리 (Dict, List, Queue, Stack, HashSet 등)
자료구조(Data Structure)란? 데이터를 효율적으로 접근하고 조작할 수 있게 데이터 구조를 만들어 관리하는 것 - Collections은 C#에서 지원하는 자료구조 클래스 using System.Collections.Generic; 제네릭 컬렉
godgjwnsgur7.tistory.com
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;
}
}
728x90
'Programmers - C# > CodingTest 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 |