Skip to content

Commit

Permalink
2544
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangshanmeta committed Nov 21, 2024
1 parent f0449c9 commit 6a4fe8f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/2544.alternating-digit-sum.2630/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public int alternateDigitSum(int n) {
int sign = String.valueOf(n).length()%2 == 1?1:-1;
int result = 0;
while( n != 0){
result += sign*(n%10);
n /= 10;
sign *= -1;
}
return result;
}
}

0 comments on commit 6a4fe8f

Please sign in to comment.