Algorithm/프로그래머스
2023.06.22
class Solution { public int[] solution(int[] arr, int k) { int[] answer = arr; boolean isEven = k % 2 == 0; for (int i = 0; i < answer.length; i++) { answer[i] = isEven ? answer[i] + k : answer[i] * k; } return answer; } }
Algorithm/프로그래머스
2023.06.21
import java.util.Arrays; import java.util.function.Predicate; class Solution { public int[] solution(int[] arr, int[] delete_list) { return Arrays.stream(arr).boxed() .filter(a -> Arrays.stream(delete_list).boxed().noneMatch(Predicate.isEqual(a))) .mapToInt(Integer::intValue).toArray(); } } 다른 사람의 풀이 import java.util.stream.IntStream; class Solution { public int[] solution(int[] arr, int[] delet..
Algorithm/프로그래머스
2023.06.20
class Solution { public int[][] solution(int n) { int[][] answer = new int[n][n]; for (int i = 0; i < n; i++) { answer[i][i] = 1; } return answer; } }
Algorithm/프로그래머스
2023.06.19
import java.util.Arrays; import java.util.stream.Collectors; class Solution { public String solution(String myString) { return Arrays.stream(myString.split("")) .map(s -> s.charAt(0) < 108 ? s.replace(s, "l") : s) .collect(Collectors.joining()); } }
Algorithm/프로그래머스
2023.06.19
import java.math.BigInteger; class Solution { public String solution(String a, String b) { return new BigInteger(a).add(new BigInteger(b)).toString(); } }
Algorithm/프로그래머스
2023.06.18
import java.time.LocalDateTime; class Solution { public int solution(int[] date1, int[] date2) { LocalDateTime dateA = LocalDateTime.of(date1[0], date1[1], date1[2], 0, 0); LocalDateTime dateB = LocalDateTime.of(date2[0], date2[1], date2[2], 0, 0); return dateA.isAfter(dateB) || dateA.isEqual(dateB) ? 0 : 1; } }
Algorithm/프로그래머스
2023.06.18
class Solution { public int solution(String[] order) { int answer = 0; for (String s : order) { if (s.contains("americano")) { answer += 4500; } else if (s.contains("cafelatte")) { answer += 5000; } else { answer += 4500; } } return answer; } }
Algorithm/프로그래머스
2023.06.15
class Solution { public int solution(int a, int b) { boolean isOddA = a % 2 != 0; boolean isOddB = b % 2 != 0; if (isOddA && isOddB) { return a*a + b*b; } else if (isOddA || isOddB) { return 2 * (a + b); } else { return Math.abs(a - b); } } }