강의로 돌아가기
HelloWorld-jh

Cannot find symbol

Set 선언에서 Cannot find symbol 오류가 자꾸 뜹니다 ㅠㅠ
스펠링이나 문법을 잘못 알고 있나 꼼꼼히 확인했지만 이유를 모르겠어서 질문드려요
컴파일 오류의 원인이 뭘까요..

import java.util.Arrays;
import java.util.Set;

public class Solution {
public int solution(int[] nums) {
int getMaxValue = nums.length / 2;
int answer = 0;

// int[] distinct = Arrays.stream(nums)
// .distinct()
// .toArray();

// int deduplication = distinct.length;

    Set<Integer> distinct = new HashSet<>();

    for (int num : nums) {
        distinct.add(num);
    }
    int deduplication = distinct.size();

    if (getMaxValue > deduplication) {
        answer = getMaxValue;
    }

    else { answer = deduplication; }

    return answer;

}

}

작성중인 코드―Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Arrays;
import java.util.Set;

public class Solution {
    public int solution(int[] nums) {
        int getMaxValue = nums.length / 2;
        int answer = 0;

//       int[] distinct = Arrays.stream(nums)
//           .distinct()
//           .toArray();

//       int deduplication = distinct.length;

        Set<Integer> distinct = new HashSet<>();

        for (int num : nums) {
            distinct.add(num);
        }
        int deduplication = distinct.size();

        if (getMaxValue > deduplication) {
            answer = getMaxValue;
        }

        else { answer = deduplication; }

        return answer;

    }

}

  • HelloWorld-jh

    hashSet 별도로 추가해주니까 통과되었습니다

    HelloWorld-jh―2023.03.02 22:15
0 개의 답변
답변 쓰기
이 입력폼은 마크다운 문법을 지원합니다.