Algorithm/Programmers
[ํ๋ก๊ทธ๋๋จธ์ค] ์ค๋ณต๋ ์ซ์ ๊ฐ์
_silver
2025. 3. 30. 02:19
๋ฌธ์ 1. ์ค๋ณต๋ ์ซ์ ๊ฐ์
โ๏ธ ๋ฌธ์ ๋ฐ๋ก ํ๊ธฐ ํด๋ฆญ

๋์ ๋ฌธ์ ํ์ด [ +1]
class Solution {
public int solution(int[] array, int n) {
// int ๊ฐ์ ์นด์ดํธํ ์์ ๋ฒํธ 0์ผ๋ก ์ด๊ธฐํ
int count = 0;
// i๋ 0๋ถํฐ array์ ๊ธธ์ด๋งํผ ๋ฐ๋ณตํด์ 1์ฉ ์ฆ๊ฐ
for(int i = 0; i < array.length; i++) {
// ๋ง์ฝ int[] ๋ฐฐ์ด์ i๋ฒ์งธ ์ซ์๊ฐ ์ ์ n๊ณผ ๋์ผํ๋ค๋ฉด
if(array[i] == n) {
// count์ 1์ฉ ์ฆ๊ฐ
count++;
}
}
// ๊ฒฐ๊ณผ๋ฅผ int count์ ๋ด๋๋ค
return count;
}
}