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
- Scrooling
- 일시정지
- Parallax
- LayerMark
- 패럴렉스
- 스크롤링
- joystick
- Blend Type
- raycast
- 플레이어 방향전환
- Object Pooling
- 유니티
- raycasting
- Ainimation Blending
- Animation State Machine
- Unity
- Transform
- 플레이어 이동
- 2D슈팅게임
- Prefabs
- CSharp #자료구조
- Hp바
- Hpbar
- Vector3
- Object Poling
- 프리팹
- rigidbody
- rotation
- apk
- 오브젝트 풀링
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 숫자 변환하기 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/154538
1. 정답코드 및 핵심 아이디어, 유의사항
- 최소 연산 횟수를 구하는 문제기 때문에 연산 전, 후로 구분하여 체크
- 연산 전 List<T>, 연산 후 HashSet<T>
https://godgjwnsgur7.tistory.com/46
using System;
using System.Collections.Generic;
public class Solution
{
public int solution(int x, int y, int n)
{
int answer = 0; // 연산 카운트
List<int> list = new List<int>(); // 연산 전
HashSet<int> hs = new HashSet<int>(); // 연산 후
// 초기 값
list.Add(x);
// 예외처리
if (x == y)
return 0;
// 연산 할 대상이 없을 때까지 수행
while (list.Count != 0)
{
answer++;
// 연산
foreach (int num in list)
{
if (num > y)
continue;
hs.Add(num + n);
hs.Add(num * 2);
hs.Add(num * 3);
}
// 값 찾음
if (hs.Contains(y))
return answer;
// 연산 전, 후 세팅
list.Clear();
list = new List<int>(hs);
hs.Clear();
}
return -1; // 불가능
}
}
728x90
'Programmers - C# > CodingTest Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 시소 짝꿍 (0) | 2023.10.13 |
---|---|
[프로그래머스 C#] Lv.2 뒤에 있는 큰 수 찾기 (0) | 2023.09.18 |
[프로그래머스 C#] Lv.2 타겟 넘버 (0) | 2023.09.05 |
[프로그래머스 C#] Lv.2 기능개발 (0) | 2023.09.03 |
[프로그래머스 C#] Lv.2 연속된 부분 수열의 합 (0) | 2023.08.30 |