2544. Alternating Digit Sum
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 Exp
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start