---
# System prepended metadata

title: 2535. Difference Between Element Sum and Digit Sum of an Array
tags: [Leetcode]

---

<style>
    html, body, .ui-content {
    background: #222222;
    color: #00BFFF;
}
    /* 設定 code 模板 */
    .markdown-body code,
.markdown-body tt {
    background-color: #ffffff36;
}
.markdown-body .highlight pre,
.markdown-body pre {
    color: #ddd;
    background-color: #00000036;
}
.hljs-tag {
    color: #ddd;
}
.token.operator {
  background-color: transparent;
}
   
</style>

###### tags: `Leetcode`

# 2535. Difference Between Element Sum and Digit Sum of an Array

###### Link : https://leetcode.com/contest/weekly-contest-328/problems/difference-between-element-sum-and-digit-sum-of-an-array/

## 題目
所有數字加總扣掉每位數字加總
## 程式碼

```cpp=
class Solution {
public:
    int differenceOfSum(vector<int>& nums) {
        int ans=0;
        for(int i=0; i < nums.size();i++)
            if(nums[i] > 9)
                ans += nums[i] - count(nums[i]);
        return ans;
    }
    int count(int num){
        int ret=0;
        while(num>0){
            ret += num%10;
            num /= 10;
        }
        return ret;
    }
};
```