String to Integer Java


  • 0
    R

    class Solution {
    public int myAtoi(String str) {
    int x= 0;
    for(int i = 0; i < str.length(); i++) {
    if(Character.isDigit(str.charAt(i))) {
    x = x*10 + (int)str.charAt(i) - 48;
    }
    }
    return x;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.