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
- 백준 c++ 2468번
- 2870번 c++
- 2870번 수학숙제 c++
- 백준 1103번
- Algorithm
- 백준 c++ 2870번
- 2870번 수학숙제
- 백준 17070번
- 백준 17070번 c++
- 백준 2870번
- Unity
- 프로그래머스
- 오브젝트 풀링
- 백준 1103번 c++
- 백준 1103번 게임
- 2870번
- 2468 c++
- 17070번
- 코테
- 코딩테스트
- C#
- 플레이어 이동
- c++
- Beakjoon
- Lv.3
- 수학숙제
- 유니티
- Lv2
- 백준
- dfs
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 스킬트리 본문
https://school.programmers.co.kr/learn/courses/30/lessons/49993
1. 정답코드 및 핵심 아이디어, 유의사항
- 선행스킬만 확인하면 되는 문제로, 스택에 담아서 순서대로 체크만 하면 된다.
- Stack<T> : LIFO (후입선출) 방식
using System;
using System.Collections.Generic;
public class Solution
{
public int solution(string skill, string[] skill_trees)
{
int answer = 0;
Stack<Char> stack = new Stack<Char>();
foreach (string str in skill_trees)
{
stack.Clear();
for (int i = skill.Length - 1; i >= 0; i--)
stack.Push(skill[i]); // 스택에 선행스킬의 순서를 역순으로 담기
bool isCheck = false;
for (int i = 0; i < str.Length; i++)
{
if (stack.Count == 0)
break;
else if (str[i] == stack.Peek()) // 선행스킬 발견
stack.Pop();
else if (stack.Contains(str[i])) // 선행스킬 미존재
{
isCheck = true;
break;
}
}
if (isCheck == false)
answer++;
}
return answer;
}
}
'CodingTest > Programmers Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 귤 고르기 (0) | 2023.08.25 |
---|---|
[프로그래머스 C#] Lv.2 k진수에서 소수 개수 구하기 (0) | 2023.08.25 |
[프로그래머스 C#] Lv.2 호텔 대실 (0) | 2023.08.23 |
[프로그래머스 C#] Lv.2 소수 찾기 (2) | 2023.08.23 |
[프로그래머스 C#] Lv.2 주식가격 (0) | 2023.08.23 |