

class Solution {
public int solution(String my_string) {
int answer = 0;
String[] str = my_string.replaceAll("[a-zA-Z]", " ").split(" ");
for (String s : str) {
if (!s.equals("")) {
answer += Integer.parseInt(s);
}
}
return answer;
}
}
문제의 조건 중 소문자, 대문자, 자연수로만 구성되어있다.


import java.util.*;
class Solution {
public int solution(int[][] board) {
ArrayList<int[]> list = new ArrayList<>();
int answer = 0;
int[] dx = {0,1,-1,0,-1,1,1,-1};
int[] dy = {1,0,0,-1,-1,1,-1,1};
for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[0].length; j++){
if(board[i][j] == 1){
int[] temp = {i,j};
list.add(temp);
}
}
}
for(int a = 0 ; a < list.size(); a++){
int i = list.get(a)[0];
int j = list.get(a)[1];
for(int k = 0 ; k < 8; k++){
if(dx[k] + i >= 0 && dy[k] + j >= 0 && dx[k] + i <= board.length-1 && dy[k] + j <= board.length-1)
board[dx[k] + i][dy[k] + j] = 1;
}
}
for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[0].length; j++){
if(board[i][j] == 0) answer+=1;
}
}
return answer;
}
}

import java.util.*;
class Solution {
public int solution(int[] sides) {
int answer = 0;
// 오름차순 정렬
Arrays.sort(sides);
int max = sides[1];
int min = sides[0];
int low_range = max - min;
int high_range = max + min;
answer = high_range - low_range - 1;
return answer;
}
}

class Solution {
public int solution(String[] spell, String[] dic) {
boolean wordCheck = false;
for (String word : dic) {
int count = 0;
for (String s : spell) {
if (word.contains(s)) count++;
}
if (count == spell.length) {
wordCheck = true;
break;
}
}
return wordCheck ? 1 : 2;
}
}