Skip to content

Commit a7eeee2

Browse files
authored
Fix: NumberFormatException with non-ASCII Unicode digits in MyAtoi (#7231)
Fix myAtoi handling of non-ASCII Unicode digits
1 parent 0f9139d commit a7eeee2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/com/thealgorithms/strings/MyAtoi.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public static int myAtoi(String s) {
4545
int number = 0;
4646
while (index < length) {
4747
char ch = s.charAt(index);
48-
if (!Character.isDigit(ch)) {
48+
49+
// Accept only ASCII digits
50+
if (ch < '0' || ch > '9') {
4951
break;
5052
}
5153

0 commit comments

Comments
 (0)