Programmer:)
[ 프로그래머스 / C# ] 혼자놀기의 달인 본문
반응형
문제 :
https://school.programmers.co.kr/learn/courses/30/lessons/131130#qna
내가 제출한 코드 :
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public int solution(int[] cards) {
int answer = 0;
List<int> indexList = new List<int>();
for (int i = 1; i <= cards.Count(); i++)
{
indexList.Add(i);
}
List<int> AllBoxList = cards.ToList(); //모든 박스 카드 값
//List<int> checkBoxIndexList = new List<int>(); //열었던 박스 인덱스
List<int> boxCountList = new List<int>(); //한타임에 연결되었던 상자의 수 모음
List<int> current_IndexList = new List<int>(); //지금 도는 루트의 인덱스 모음
int index = 1; //현재인덱스
int nextIndex = 0; //다음 인덱스
int count = AllBoxList.Count();
for (int i = 1; i <= count; i++)
{
nextIndex = AllBoxList[index-1];
current_IndexList.Add(index);
if (current_IndexList.Contains(nextIndex) == true)
{
boxCountList.Add(current_IndexList.Count);
indexList = indexList.Except(current_IndexList).ToList();
if (indexList.Count() == 0)
break;
else
index = indexList[0];
current_IndexList = new List<int>();
}
else
index = nextIndex;
}
if (boxCountList.Count >= 2)
{
boxCountList.Sort();
boxCountList.Reverse();
answer = boxCountList[0] * boxCountList[1];
return answer;
}
else
{
return answer;
}
}
}
,,,,?
문제도 이해가 잘 안가서 긴가민가 만들어서 제출했는데 통과한 알고리즘..
성장한것일까..?
문제가 재미없어서 따로 분석을 없다 (아직도 이해를 잘 못하겠음)
반응형
'프로그래머스 정복 > C#' 카테고리의 다른 글
최댓값과 최솟값 (Select 이용) (0) | 2023.04.03 |
---|---|
[ 프로그래머스 / C# ] 옹알이 (1) (0) | 2022.11.24 |
[ 프로그래머스 / C# ] 숫자 카드 나누기 (0) | 2022.11.18 |
[ 프로그래머스 / C# ] 과일 장수 (0) | 2022.11.16 |
[ 프로그래머스 / C# ] K번째 수 (0) | 2022.03.29 |
Comments