class Solution { public int solution(String my_string) { int answer = 0; int curr = 0; boolean isNumber = false; for (int i = 0; i < my_string.length(); i++) { char ch = my_string.charAt(i); if (Character.isDigit(ch)) { curr = curr * 10 + ch - '0'; isNumber = true; } else { if (isNumber) { answer += curr; curr = 0; isNumber = false; } } } if (isNumber) answer += curr; return answer; } }