A simple for loop from the end of str(in c++)


  • 0
    S

    '''
    class Solution {
    public:
    int lengthOfLastWord(string s) {
    int rst = 0 ;
    for(int i = s.length()-1; i>=0; i--){
    if(s[i]!=' ') rst++;
    else if(rst != 0) break;
    }
    return rst;
    }
    };
    ''''


  • 0

    @Sublele Hi, You are using 3 single quote to format your code, which is wrong. To format your code, use 3 backticks.

    Like this:

    ```
    Your code here
    ```

Log in to reply
 

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