답안 :
import java.util.Arrays;
public class Solution {
public int solution(int n, int m, int[] section) {
int answer = 0;
boolean[] wall = new boolean[n];
Arrays.fill(wall, true);
//칠해야할 벽면 idx false 화.
for (int i = 0; i < section.length; i++) {
wall[section[i] - 1] = false;
}
for (int i = 0; i < n; i++) {
// 벽면을 칠해야할때
if (!wall[i]) {
//m만큼 페인트칠
for (int j = 0; j < m; j++) {
//최댓값 검사(OutOfBound 예방)
if (i + j < wall.length) {
wall[i + j] = true;
}
}
//칠한만큼 인덱스이동
i = i + m - 1;
answer++;
}
}
return answer;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Solution s = new Solution();
int n = 8;
int m = 4;
int[] section = { 2, 3, 6 };
System.out.println(s.solution(n, m, section));
}
}
package answer;
import java.util.ArrayList;
public class Solution {
public int solution(int n, int m, int[] section) {
int answer = 0;
int sumwall = 0;
ArrayList<Integer> arr1 = new ArrayList<>();
for (int i = 0; i < section.length; i++) {
sumwall += section[i];
}
for (int i = 1; i <= n; i++) {
arr1.add(i);
}
for (int i = 0; i < sumwall / m; i++) {
for (int j = 0; j < section.length; j++) {
if (arr1.contains(section[j]) && arr1.size() > m) {
if (arr1.get(arr1.size() - 1) < section[j] - 1 + m) {
arr1.subList(section[j] - 1, arr1.size() - 1).clear();
answer++;
}
arr1.subList(section[j] - 1, section[j] - 1 + m).clear();
answer++;
} else if (arr1.contains(section[j]) && arr1.size() <= m) {
arr1.clear();
answer++;
}
}
}
return answer;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Solution s = new Solution();
int n = 4;
int m = 1;
int[] section = { 1,2,3,4 };
System.out.println(s.solution(n, m, section));
}
}
참조 :
https://hianna.tistory.com/556
https://wtg-study.tistory.com/25
select car_id,
case when MAX('2022-10-16' Between Start_date and End_date) then '대여중'
else '대여 가능' end as 'AVAILABILITY'
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
group by car_id
order by car_id desc
SELECT
CAR_ID,
CASE
WHEN EXISTS (
SELECT 1
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY AS sub
WHERE sub.CAR_ID = main.CAR_ID
AND '2022-10-16' BETWEEN sub.START_DATE AND sub.END_DATE
) THEN '대여중'
ELSE '대여 가능'
END AS AVAILABILITY
FROM
CAR_RENTAL_COMPANY_RENTAL_HISTORY AS main
GROUP BY
CAR_ID
ORDER BY
CAR_ID DESC;