프로그래머스 C# 중복된 숫자 개수(파이썬, 자바)
2023. 4. 8. 00:19ㆍC# 알고리즘 코딩(프로그래머스)
using System;
public class Solution {
public int solution(int[] array, int n) {
int answer = 0;
for(int i = 0; i < array.Length; i++)
{
if(array[i] == n) // 어레이의 몇 번째에 n이랑 같은 게 있는 지 확인하기
{
answer++;
}
}
return answer;
}
}
//////
using System;
public class Solution {
public int solution(int[] array, int n) {
int answer = 0;
foreach (var it in array)
{
if (it == n)
{
answer++;
}
}
return answer;
}
}
//foreach로 꼭 it라고 하지 않아도 된다.
파이썬
def solution(array, n):
return array.count(n)
자바
class Solution {
public int solution(int[] array, int n) {
int answer = 0;
for (int num : array)
{
if (num == n) answer++;
}
return answer;
}
}
'C# 알고리즘 코딩(프로그래머스)' 카테고리의 다른 글
프로그래머스 C# 배열 안에 있는 수를 2배씩 하기 (0) | 2023.04.10 |
---|---|
프로그래머스 C# 양꼬치(파이썬, 자바) (0) | 2023.04.09 |
프로그래머스 C# 배열의 평균값(Linq, Average) (0) | 2023.04.06 |
프로그래머스 C# 양꼬치(파이썬, 자바) (0) | 2023.04.05 |
프로그래머스 C# 짝수의 합(파이썬, 자바) (0) | 2023.04.03 |