• Length of Last Word


     1 public class Solution {
     2     public int lengthOfLastWord(String s) {
     3         // IMPORTANT: Please reset any member data you declared, as
     4         // the same Solution instance will be reused for each test case.
     5         if(s == null)
     6             return 0;
     7         char[] mychar = s.trim().toCharArray();
     8         int count = 0;
     9         for(int i=0; i<mychar.length; i++)
    10         {
    11             char tmp = mychar[i];
    12             if(tmp == ' ')
    13                 count = 0;
    14             else if((tmp >= 'A' && tmp <= 'Z')||(tmp >= 'a' && tmp <= 'z'))
    15                 count++;
    16             else{
    17                 count = 0;
    18                 do{i++;}while(mychar[i] != ' '&&i<mychar.length);
    19             }
    20         }
    21         return count;
    22     }
    23 }
  • 相关阅读:
    2020/5/8
    2020/5/8
    2020/5/6
    2020/4/30
    2020/4/29
    2020/4/28
    2020/4/27
    KMP算法详解
    博客搬家声明
    洛谷P2831 NOIP2016 愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/jasonC/p/3408786.html
Copyright © 2020-2023  润新知