SELECT i.INGREDIENT_TYPE, SUM(h.TOTAL_ORDER) AS TOTAL_ORDER FROM FIRST_HALF h LEFT JOIN ICECREAM_INFO i GROUP BY i.FLAVOR
SELECT i.INGREDIENT_TYPE, SUM(h.TOTAL_ORDER) AS TOTAL_ORDER FROM FIRST_HALF h JOIN ICECREAM_INFO i ON h.FLAVOR = i.FLAVOR GROUP BY i.INGREDIENT_TYPE ORDER BY TOTAL_ORDER
import java.util.*;
public class Solution {
public int[] solution(int []arr) {
Stack<Integer> stack = new Stack<>();
for(int num : arr) {
if(stack.isEmpty() || stack.peek() != num) {
stack.push(num);
}
}
int[] answer = new int [stack.size()];
for(int i = answer.length -1;i>=0;i--) {
answer[i] = stack.pop();
}
return answer;
}
}
스택이 비어있거나, 맨 위 원소(직전 숫자)와 현재 숫자가 다를 때만 push함
stack.pop()은 뒤에서부터 원소를 꺼내므로, 배열의 맨 뒤 인덱스(answer.length - 1)부터 역순으로 채워넣어야 입력 순서가 유지됨
import java.util.*;
public class Solution {
public int[] solution(int []arr) {
ArrayList<Integer> tempList = new ArrayList<Integer>();
int preNum = 10;
for(int num : arr) {
if(preNum != num)
tempList.add(num);
preNum = num;
}
int[] answer = new int[tempList.size()];
for(int i=0; i<answer.length; i++) {
answer[i] = tempList.get(i).intValue();
}
return answer;
}
}

3. 부족한 금액 계산하기
잔액에서 이용료 제외하고, 또 제외하고 해서 count만큼 반복하면 될거같음
class Solution {
public long solution(int price, int money, int count) {
long answer = 0;
for(int i=1;i<=count;i++) {
money- price * i;
}
if(money > 0) {
return 0;
} else {
return money *-1;
}
}
}
class Solution {
public long solution(int price, int money, int count) {
long totalCost = 0;
for(int i=1;i<=count;i++) {
totalCost += (long) price * i;
}
long diff = totalCost - money;
return diff > 0 ? diff : 0;
}
}
class Solution {
public long solution(int price, int money, int count) {
long totalCost = (long) price * count * (count + 1) / 2;
return totalCost > money ? totalCost - money : 0;
}
}
1부터 count까지의 합은 등차수열의 합 공식()을 활용할 수도 있습니다.