- 중복된 숫자 개수
- 배열의 평균값
- 짝수 홀수 개수
- 배열 자르기
- 배열 원소의 길이
- 배열 뒤집기
- 최댓값 만들기
class Solution {
public int solution(int[] array, int n) {
int answer = 0;
for(int i=0; i < array.length; i++)
if(array[i] == n) {
answer++;
}
return answer;
}
}
class Solution {
public double solution(int[] numbers) {
double answer = 0;
int total = 0;
for(int i = 0; i < numbers.length; i++) {
total += numbers[i];
}
answer = (double)total / numbers.length;
return answer;
}
}
class Solution {
public int[] solution(int[] num_list) {
int[] answer = new int[2];
int left = 0;
int right = 0;
for(int i = 0; i < num_list.length; i++) {
if (num_list[i] % 2 == 0) {
left++;
}
else {
right++;
}
}
answer[0] = left;
answer[1] = right;
return answer;
}
}
import java.util.Arrays;
class Solution {
public int[] solution(int[] numbers, int num1, int num2) {
int[] answer = {};
answer = Arrays.copyOfRange(numbers, num1, num2+1);
return answer;
}
}
class Solution {
public int[] solution(String[] strlist) {
int[] answer = new int[strlist.length];
for (int i = 0; i < answer.length; i++) {
answer[i] = strlist[i].length();
}
return answer;
}
}
다시보기
class Solution {
public int[] solution(int[] num_list) {
int[] answer = new int[num_list.length];
for(int i = 0;i<num_list.length;i++){
answer[i]=num_list[num_list.length-i-1];
}
return answer;
}
}
class Solution {
public int solution(int[] numbers) {
int answer = 0;
int max = 0;
for(int i = 0; i < numbers.length; i++) {
for (int j = i + 1; j < numbers.length; j++) {
if (numbers[i] * numbers[j] > max) {
max = numbers[i] * numbers[j];
}
}
}
answer = max;
return answer;
}
}