• Skip to primary navigation
  • Skip to content
  • Skip to footer
zhicheng xie's demo blog
  • Quick-Start Guide

    Your Name

    I am an amazing person.

    • Somewhere

    Subtract the Product and Sum of Digits of an Integer

    less than 1 minute read

    <-E> Subtract the Product and Sum of Digits of an Integer

    class Solution {
    public:
        
        int subtractProductAndSum(int n) {
            int a = 1;
            int b = 0;
            int x;
            while (n != 0) {
                x = n % 10;
                a *= x;
                b += x;
                n = n / 10;
            }
            return a - b;
        }
        
    };
    

    Tags: Algorithms, C++, Leetcode

    Updated: January 12, 2020

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Decode Ways

    less than 1 minute read

    <-M 91> Decode Ways

    Word Break

    less than 1 minute read

    <-H 139> Word Break

    Distinct Subsequences

    less than 1 minute read

    <-H 115> Distinct Subsequences

    Edit Distance

    less than 1 minute read

    <-H 72> Edit Distance

    • Follow:
    • Feed
    © 2023 zhicheng xie's blog. Powered by Jekyll & Minimal Mistakes.