img: https://www.logicbig.com/tutorials/core-java-tutorial/java-util-stream/stream-api-intro.html
doc: https://docs.oracle.com/javase/tutorial/collections/streams/index.html
source: https://school.programmers.co.kr/learn/courses/30/lessons/120831
also refer: https://www.baeldung.com/java-8-streams
recall: https://velog.io/@khchoo/1%EC%A3%BC%EC%B0%A8-%EB%AA%A9%EC%9A%94%EC%9D%BC
Array Manipulations 참고
class Solution {
public int solution(int n) {
int k = 0;
if(n==1){
return 0;
}
else if(n%2==0){
k = n/2;
return getSum(k);
}
else{
k = (n-1)/2;
return getSum(k);
}
}
private int getSum(int a){return a*(a+1);}
}
import java.util.stream.IntStream;
class Solution {
public int solution(int n) {
return IntStream.rangeClosed(0, n)
.filter(e -> e % 2 == 0)
.sum();
}
}