프로그래머스 (접두사인지 확인하기)
public class problem385 {
class Solution {
public int solution(String my_string, String is_prefix) {
int answer = 0;
// startsWith() : () 에있는 문자열로 시작하는지 검증,
// true false 반환
if(my_string.startsWith(is_prefix)){
answer = 1;
}
return answer;
}
}
}
프로그래머스 (꼬리 문자열)
public class problem386 {
class Solution {
public String solution(String[] str_list, String ex) {
String answer = "";
for(int i = 0; i < str_list.length; i++){
// str_list 배열에서 ex 문자열을 포함하고 있으면 continue
if(str_list[i].contains(ex)){
continue;
}else{
answer += str_list[i];
}
}
return answer;
}
}
}
프로그래머스 (부분 문자열 이어 붙여 문자열 만들기)
public class problem387 {
class Solution {
public String solution(String[] my_strings, int[][] parts) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < my_strings.length; i++){
int start = parts[i][0]; // 시작 인덱스
int end = parts[i][1]; // 끝 인덱스
sb.append(my_strings[i].substring(start, end + 1));
}
return sb.toString();
}
}
}
프로그래머스 (순서 바꾸기)
public class problem388 {
class Solution {
public int[] solution(int[] num_list, int n) {
int[] result = new int[num_list.length];
// n 번째 까지의 원소
for (int i = 0; i < n; i++) {
result[i + num_list.length - n] = num_list[i];
}
// n 번째 이후의 원소
for (int j = 0; j < num_list.length - n; j++) {
result[j] = num_list[n + j];
}
return result;
}
}
}