4line solution without ant builtin function 0ms


  • 0
    M
    int last = 0, len = s.length(); 
    while(len > 0 && s.charAt(len-1) == ' ') --len;
    while(len > 0 && s.charAt(--len) != ' ') last++;
    return last;

Log in to reply
 

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