목록분류 전체보기 (150)
코딩응급실
import java.util.*; class Solution { public String solution(String s) { String answer = ""; String[] words = s.toLowerCase().split(""); boolean flag = true; for(String str : words) { answer += flag ? str.toUpperCase() : str; flag = str.equals(" ") ? true : false; } return answer; } public static void main(String[] args) { String s = "3people unFollowed me"; Solution sol = new Solution(); String ..
import java.util.*; class Solution { public int solution(int[] nums) { HashMap map = new HashMap(); for (int i = 0; i nums.length / 2 ? nums.length / 2 : map.size(); } public static void main(String[] args) { int[] arr = {3,1,2,3}; Solution sol = new Solution(); System.out.println(sol.solution(arr)); } }
import java.util.*; class Solution { public String solution(int a, int b) { String answer = ""; int[] c = {31,29,31,30,31,30,31,31,30,31,30,31}; String[] MM ={"FRI","SAT","SUN","MON","TUE","WED","THU"}; int Adate = 0; for(int i = 0 ; i< a-1; i++){ Adate += c[i]; } Adate += b-1; answer = MM[Adate % 7]; return answer; } public static void main(String[] args) { int a = 5; int b = 24; Solution sol =..
import java.util.*; class Solution { public String solution(String s) { String answer = ""; if (s.length() % 2 == 0) { answer += s.charAt(s.length() / 2 - 1); answer += s.charAt(s.length() / 2); } else { answer += s.charAt(s.length() / 2); } return answer; } public static void main(String[] args) { String s = "abcde"; Solution sol = new Solution(); String result = sol.solution(s); System.out.pri..
import java.util.*; public class Solution { public int[] solution(int []arr) { Stack stack = new Stack(); for (int i=0; i=0; i--) { answer[i] = stack.pop(); } return answer; } public static void main(String[] args) { int[] arr = {1,1,3,3,0,1,1}; Solution sol = new Solution(); int[] result = sol.solution(arr); // 결과 배열을 출력 System.out.println(Arrays.toString(result)); } }
import java.util.*; class Solution { public int[] solution(int[] arr, int divisor) { ArrayList list = new ArrayList(); for (int i = 0; i < arr.length; i++) { if (arr[i] % divisor == 0) { list.add(arr[i]); } } if (list.size() == 0) { list.add(-1); } Collections.sort(list); int[] answer = new int[list.size()]; for (int i = 0; i < list.size(); i++) { answer[i] = list.get(i); } return answer; } publ..
import java.util.*; class Solution { public long solution(int a, int b) { int max = Math.max(a, b); int min = Math.min(a, b); return (long)(min + max) * (max - min + 1) / 2; } public static void main(String[] args) { int a = 3; int b = 5; Solution sol = new Solution(); long result = sol.solution(a, b); System.out.println(result); // 출력: 12 } } 가우스 공식 사랑해요 보통 1~N 까지면 S = n * (n+1) // 2 이고, N ~ M ..
import java.util.*; class Solution { public String[] solution(String[] strings, int n) { Arrays.sort(strings, new Comparator() { @Override public int compare(String s1, String s2) { if (s1.charAt(n) > s2.charAt(n)) { return 1; } else if (s1.charAt(n) == s2.charAt(n)) { return s1.compareTo(s2); } else { return -1; } } }); return strings; } public static void main(String[] args) { Solution sol = n..