158. 숨어있는 숫자의 덧셈 (2)

김해준's avatar
Dec 30, 2025
158. 숨어있는 숫자의 덧셈 (2)

사용언어 : Java

문제
notion image
풀이
import java.util.*; class Solution { public int solution(String my_string) { ArrayList<String> arr = new ArrayList(); int index = 0; arr.add("0"); for(int i = 0 ; i < my_string.length(); i++) { String temp = arr.get(index); char c = my_string.charAt(i); if(Character.isDigit(c)) { temp+=c; arr.set(index,temp); } else { if(temp.length() > 0) { arr.add("0"); index++; } } } int answer = 0; for(var c : arr) { String temp = ""; temp += c; answer += Integer.parseInt(temp); } return answer; } }
억지로 풀어버린 문제다
이거보다 더 나은 방법은 분명 있을것이다
Share article