Develop

[프로그래머스] Error :: bad return type in lambda expression 본문

개인 공부/프로그래머스

[프로그래머스] Error :: bad return type in lambda expression

개발 기록 2024. 1. 27. 16:54

 

https://sseb32310.tistory.com/52

 

[프로그래머스] 수열과 구간 쿼리2

문제 내풀이 class Solution { public int[] solution(int[] arr, int[][] queries) { int[] answer = new int[queries.length]; int z = 0; int check=0; int answerMin = 10000001; // for문 - 배열의 길이 만큼 for(int i=0; i < queries.length; i++){ check

sseb32310.tistory.com

이 프로그래머스 문제를 stream으로 풀다가 난 오류

 

 

이게 무슨 오류인가 싶어서 찾아보았는데

람다표현식 리스트 -> 배열로 변경하면서 나오는 타입문제라고 한다.

 

해결 방법

: List를 만들어줄 때 타입을 지정하기

List<Integer> answer = new ArrayList();

or

List<Integer> answer = newArrayList<Integer>();

 

but 나는 괄호를 제대로 열고 닫지 않아서 나온 에러였다..

.toArray()가 밖에 있어야하는데 안에 입력해서 이상한거였음!


 

참고한 글

https://acet.pe.kr/963

 

콜라츠 수열 - error: incompatible types: bad return type in lambda expression .mapToInt(i -> i)

코딩 테스트 난이도 (하)에서 콜라츠 수열이라는걸 알게 되었다. 세상에 이런일이! ㅋㅋ 반드시 x가 1이된다니.. 모든 자연수 x에 대해서 현재 값이 x이면 x가 짝수일 때는 2로 나누고, x가 홀수일

acet.pe.kr