Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package g3701_3800.s3754_concatenate_non_zero_digits_and_multiply_by_sum_i;

// #Easy #Math #Mid_Level #Weekly_Contest_477
// #2026_04_25_Time_1_ms_(100.00%)_Space_42.50_MB_(73.85%)

public class Solution {
public long sumAndMultiply(int n) {
int newNum = 0;
int y = Math.abs(n);
while (y > 0) {
int rem = y % 10;
if (rem != 0) {
newNum = newNum * 10 + rem;
}
y /= 10;
}
int temp = 0;
while (newNum > 0) {
int rem = newNum % 10;
temp = temp * 10 + rem;
newNum /= 10;
}
int x = temp;
long sum = 0;
while (temp > 0) {
int rem = temp % 10;
sum += rem;
temp /= 10;
}
return sum * x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
3754\. Concatenate Non-Zero Digits and Multiply by Sum I

Easy

You are given an integer `n`.

Form a new integer `x` by concatenating all the **non-zero digits** of `n` in their original order. If there are no **non-zero** digits, `x = 0`.

Let `sum` be the **sum of digits** in `x`.

Return an integer representing the value of `x * sum`.

**Example 1:**

**Input:** n = 10203004

**Output:** 12340

**Explanation:**

* The non-zero digits are 1, 2, 3, and 4. Thus, `x = 1234`.
* The sum of digits is `sum = 1 + 2 + 3 + 4 = 10`.
* Therefore, the answer is `x * sum = 1234 * 10 = 12340`.

**Example 2:**

**Input:** n = 1000

**Output:** 1

**Explanation:**

* The non-zero digit is 1, so `x = 1` and `sum = 1`.
* Therefore, the answer is `x * sum = 1 * 1 = 1`.

**Constraints:**

* <code>0 <= n <= 10<sup>9</sup></code>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package g3701_3800.s3754_concatenate_non_zero_digits_and_multiply_by_sum_i;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.jupiter.api.Test;

class SolutionTest {
@Test
void sumAndMultiply() {
assertThat(new Solution().sumAndMultiply(10203004), equalTo(12340L));
}

@Test
void sumAndMultiply2() {
assertThat(new Solution().sumAndMultiply(1000), equalTo(1L));
}
}
Loading