leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0058.cpp (246B)


      1 class Solution {
      2   public:
      3     int lengthOfLastWord(string s) {
      4         int i = s.size(), res = 0;
      5         while (--i >= 0 && isspace(s[i]))
      6             ;
      7         while (i >= 0 && !isspace(s[i--]))
      8             res++;
      9         return res;
     10     }
     11 };