퇴근5분전

https://okky.kr/article/505235

 

문제)

{10, 20, 20, 10, 10, 30 ,50, 10, 20};


위와 같은 배열에 한 쌍씩 짝을 지어서 남은 숫자의 개수를 세는 문제입니다.


ex)

쌍이 존재

10   10

20   20

10  10 


쌍이 존재하지 않음

30

50

20



답 : 3

 

 

풀이)

            int[] nums = { 10, 20, 20, 10, 10, 30, 50, 10, 20 };
            
            List<int> findedList = new List<int>();

            for (int loop = 0; loop < nums.Length; loop++)
            {
                if (findedList.Contains(nums[loop]))
                {
                    findedList.Remove(nums[loop]);
                }
                else
                {
                    findedList.Add(nums[loop]);
                }
            }

            int cnt = findedList.Count;

 

음 난 c#으로 풀어봄.