3754. Concatenate Non-Zero Digits and Multiply by Sum I Easy
1/**
2 * [3754] Concatenate Non-Zero Digits and Multiply by Sum I
3 *
4 * You are given an integer n.
5 * 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.
6 * Let sum be the sum of digits in x.
7 * Return an integer representing the value of x * sum.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">n = 10203004</span>
12 * Output: <span class="example-io">12340</span>
13 * Explanation:
14 *
15 * The non-zero digits are 1, 2, 3, and 4. Thus, x = 1234.
16 * The sum of digits is sum = 1 + 2 + 3 + 4 = 10.
17 * Therefore, the answer is x * sum = 1234 * 10 = 12340.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">n = 1000</span>
22 * Output: <span class="example-io">1</span>
23 * Explanation:
24 *
25 * The non-zero digit is 1, so x = 1 and sum = 1.
26 * Therefore, the answer is x * sum = 1 * 1 = 1.
27 * </div>
28 *
29 * Constraints:
30 *
31 * 0 <= n <= 10^9
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/concatenate-non-zero-digits-and-multiply-by-sum-i/
37// discuss: https://leetcode.com/problems/concatenate-non-zero-digits-and-multiply-by-sum-i/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn sum_and_multiply(n: i32) -> i64 {
43
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_3754() {
55 }
56}
57Back
© 2026 bowen.ge All Rights Reserved.