목록Java (133)
코딩응급실
public class Solution { public static void main(String[] args) { String s = "aaabbaccccabba"; // 단어 Solution sol = new Solution(); int result = sol.solution(s); System.out.println(result); } public int solution(String s) { int answer = 0; for (int x = 0; x < s.length(); x++) { char xAlpha = s.charAt(x); int xCnt = 1; int differCnt = 0; while (x + 1 < s.length() && (xCnt != differCnt)) { if (s.ch..
import java.util.Arrays; public class Solution { public static void main(String[] args) { String s = "banana"; // 단어 /* * b는 처음 나왔기 때문에 자신의 앞에 같은 글자가 없습니다. 이는 -1로 표현합니다. * a는 처음 나왔기 때문에 자신의 앞에 같은 글자가 없습니다. 이는 -1로 표현합니다. * n은 처음 나왔기 때문에 자신의 앞에 같은 글자가 없습니다. 이는 -1로 표현합니다. * a는 자신보다 두 칸 앞에 a가 있습니다. 이는 2로 표현합니다. * n도 자신보다 두 칸 앞에 n이 있습니다. 이는 2로 표현합니다. * a는 자신보다 두 칸, 네 칸 앞에 a가 있습니다. 이 중 가까운 것은 두 칸 앞이고,..
바로 런타임 에러가 발생했다. public class Solution { public static void main(String[] args) { String t = "500220839878"; // 숫자 문자열 String p = "7"; //
import java.util.*; public class Solution { public static void main(String[] args) { String today = "2022.05.19"; // 오늘 날짜 String[] terms = {"A 6", "B 12", "C 3"}; // 약관 종류 A 6달까지, B 12달까지, C 3달까지 String[] privacies = { "2021.05.02 A", "2021.07.01 B", "2022.02.19 C", "2022.02.20 C" }; // 계산하기 편하게 모든 달은 28일까지 있다고 가정한다 Solution sol = new Solution(); int[] result = sol.solution(today, terms, privac..

public class Solution { public static void main(String[] args) { String s = "aukks"; String skip = "wbqd"; int index = 5; Solution sol = new Solution(); String result1 = sol.solution(s, skip, index); System.out.println(result1); } public String solution(String s, String skip, int index) { String answer = ""; // a = 97 ~ z = 122 // aukks, wbqd, 5, happy!! /* * a의 5번째 뒤에 * b,c,d,e,f * b,d는 skip * ..
public class Solution { public static void main(String[] args) { String[] cards1 = {"i", "water", "drink"}; String[] cards2 = {"want", "to"}; String[] goal = {"i", "want", "to", "drink", "water"}; Solution sol = new Solution(); String result1 = sol.solution(cards1, cards2, goal); System.out.println(result1); } public String solution(String[] cards1, String[] cards2, String[] goal) { String answe..
import java.util.Arrays; import java.util.HashMap; public class Solution { public static void main(String[] args) { String[] keymap = {"ABACD", "BCEFD"}; String[] targets = {"ABCD", "AABB"}; Solution sol = new Solution(); int[] result1 = sol.solution(keymap, targets); System.out.println(Arrays.toString(result1)); // [9, 4] } public int[] solution(String[] keymap, String[] targets) { int[] answer..