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
- 플레이어 이동
- 프로그래머스
- Unity
- Lv2
- Algorithm
- 수학숙제
- 2870번
- 백준 17070번
- Lv.3
- 백준 c++ 2468번
- 2870번 수학숙제 c++
- 코테
- 백준 1103번 게임
- 코딩테스트
- 백준 2870번
- C#
- 유니티
- 백준 17070번 c++
- 백준 1103번 c++
- 오브젝트 풀링
- 2468 c++
- 2870번 c++
- 2870번 수학숙제
- dfs
- 백준 c++ 2870번
- c++
- Beakjoon
- 백준 1103번
- 백준
- 17070번
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.1 로또의 최고 순위와 최저 순위 본문
https://school.programmers.co.kr/learn/courses/30/lessons/77484
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 정답코드 및 핵심 아이디어, 유의사항
직관적인 문제, 주석 참조
using System;
using System.Collections.Generic;
public class Solution
{
public int[] solution(int[] lottos, int[] win_nums)
{
List<int> myList = new List<int>(lottos); // 내가 가진 로또 번호 리스트
List<int> lottoList = new List<int>(win_nums); // 로또 당첨 번호 리스트
int zeroCount = 0; // 알아볼 수 없는 번호의 개수
int count = 0; // 로또 당첨 개수
// 0의 개수 카운트
while (myList.Contains(0))
{
myList.Remove(0);
zeroCount++;
}
// 로또 당첨 개수 카운트
foreach (int num in myList)
if (lottoList.Contains(num))
count++;
int min = Function(count);
int max = Function(count + zeroCount);
return new int[2] { max, min };
}
// 맞는 개수에 따른 순위를 반환하는 메서드 (조건)
public int Function(int num)
{
if (num < 2)
return 6;
return 7 - num;
}
}
'CodingTest > Programmers Lv.1' 카테고리의 다른 글
[프로그래머스 C#] Lv.1 햄버거 만들기 (1) | 2023.12.05 |
---|---|
[프로그래머스 C#] Lv.1 체육복 (0) | 2023.11.16 |
[프로그래머스 C#] Lv.1 문자열 나누기 (0) | 2023.09.03 |
[프로그래머스 C#] Lv.1 대충 만든 자판 (0) | 2023.08.30 |
[프로그래머스 C#] Lv.1 둘만의 암호 (0) | 2023.08.23 |