로딩
요청 처리 중입니다...

JAVA_LeetCode 3754_Concatenate Non-Zero Digits and Multiply by Sum I

 JAVA_LeetCode 3754_Concatenate Non-Zero Digits and Multiply by Sum I

JAVA_LeetCode 3754_Concatenate Non-Zero Digits and Multiply by Sum I 풀이 class Solution { public long sumAndMultiply(int n) { StringBuilder sb = new StringBuilder(); int sum = 0; long x = 0; for(char c : String.valueOf(n).toCharArray()){ if(c != '0'){ sb.append(c); sum += c - '0'; } } x = sb.length() == 0 ?

0 : Long.parseLong(sb.toString()); return x * sum; } } 숫자 문자열, 합계 풀이 숫자 문자열을 문자로 변환하여 숫자가 0이 아닌경우를 찾아서 값 찾기 이후 합계와 각 숫자를 합친 숫자 문자열을 구해서 두 값을 곱해준다. * 출처 https://leetcode.com/problems/concatenat...