import java.util.ArrayList;
import java.util.List;
class Solution {
public int[] solution(int n) {
List<Integer> list = new ArrayList<>();
while (true) {
list.add(n);
if(n==1) {
break;
}
if(n %2 ==0) {
n = n /2;
} else {
n = 3*n+1;
}
}
return list.stream().mapToInt(i -> i).toArray();
}
}
class Solution {
public int[] solution(int[] arr) {
int[arr_length] stk = arr_length;
for(int i=0;i<arr_length;i++) {
if(stk.isEmpty) {
stk[i] = arr[i];
} else{
if(srk[i] < arr[i]) {
stk[i] = arr[i];
} else{
stk[i].remove;
}
}
}
return stk;
}
}
ArrayList로 list만들고, while문으로 조건에 맞게 구현하면 됨
import java.util.ArrayList;
import java.util.List;
class Solution {
public int[] solution(int[] arr) {
List<Integer> stk = new ArrayList<>();
int i = 0;
while (i < arr.length) {
if (stk.isEmpty()) {
stk.add(arr[i]);
i++;
}
else if (stk.get(stk.size() - 1) < arr[i]) {
stk.add(arr[i]);
i++;
}
else {
stk.remove(stk.size() - 1);
}
}
return stk.stream().mapToInt(val -> val).toArray();
}
}
import java.util.Stack;
class Solution {
public int[] solution(int[] arr) {
Stack<Integer> stack = new Stack<>();
for (int num : arr) {
while (!stack.isEmpty() && num <= stack.peek())
stack.pop();
stack.push(num);
}
return stack.stream().mapToInt(i -> i).toArray();
}
}
stack이용해서 문제 해결도 가능
class Solution {
public boolean solution(boolean x1, boolean x2, boolean x3, boolean x4) {
boolean answer = true;
boolean answer1 = true;
boolean answer2 = true;
if(x1 || x2 ) {
answer1 = true;
} else {
answer1 = false;
}
if(x3 || x4 )
answer2 = true;
} else {
answer 2 = false;
}
if(answer1 && answer2) {
answer = true;
} else {
answer = false;
}
return answer;
}
}
class Solution {
public boolean solution(boolean x1, boolean x2, boolean x3, boolean x4) {
return (x1 || x2) && (x3 || x4);
}
}
괄호 두 개((x1 ∨ x2), (x3 ∨ x4))를 각각 계산한 뒤에 둘을 &&로 묶어주면 됨