carloscn / carloscn/structstudy

leetcode2544: Alternating Digit Sum

Open
#416 2 comments 0 reactions 1 assignee Claimed by @carloscn View on GitHub
Lang-c/c++ Level-easy 一般问题 数学
Dominant language
C
Stars
4
Forks
1
PR merge metrics
No merged PRs in 30d

Description

### Description

You are given a positive integer n. Each digit of n has a sign according to the following rules:

The most significant digit is assigned a positive sign.
Each other digit has an opposite sign to its adjacent digits.
Return the sum of all digits with their corresponding sign.

#### Example 1:

Input: n = 521
Output: 4
Explanation: (+5) + (-2) + (+1) = 4.

#### Example 2:

Input: n = 111
Output: 1
Explanation: (+1) + (-1) + (+1) = 1.

#### Example 3:

Input: n = 886996
Output: 0
Explanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0.

#### Constraints:

1 <= n <= 109

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.