Programmer:)
[ 프로그래머스 / C# ] 없는숫자 더하기(Except) 본문
반응형
문제
https://programmers.co.kr/learn/courses/30/lessons/86051
코딩테스트 연습 - 없는 숫자 더하기
0부터 9까지의 숫자 중 일부가 들어있는 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요. 제한
programmers.co.kr
using System;
public class Solution {
public int solution(int[] numbers) {
int answer = 0;
int temp = 0;
for(int i = 0; i<numbers.Length; i++)
temp+=numbers[i];
answer= 45-temp;
return answer;
}
}
Except 활용
https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-5.0
Enumerable.Except Method (System.Linq)
Produces the set difference of two sequences.
docs.microsoft.com
using System;
using System.Linq;
public class Solution {
public int solution(int[] numbers) {
int[] numbs = new int[10]{0,1,2,3,4,5,6,7,8,9};
int answer = numbs.Except(numbers).Sum();
return answer;
}
}
반응형
'프로그래머스 정복 > C#' 카테고리의 다른 글
[ 프로그래머스 / C# ] 과일 장수 (0) | 2022.11.16 |
---|---|
[ 프로그래머스 / C# ] K번째 수 (0) | 2022.03.29 |
[ 프로그래머스 / C# ] 음양 더하기 (0) | 2021.10.25 |
[ 프로그래머스 / C# ] 숫자 문자열과 영단어(2021 카카오 채용 연계 인턴쉽)(Dictionary) (0) | 2021.10.22 |
[ 프로그래머스 / C# ] 로또의 최고 순위와 최저 순위(for/foreach) (0) | 2021.10.18 |
Comments