Java Solution for above problem


#1

public class Solution {
// DO NOT MODIFY THE ARGUMENTS WITH “final” PREFIX. IT IS READ ONLY
public int lengthOfLastWord(final String A) {
int ct=0;
char ch;
if(A.length()==1)
return 1;
String x=A.trim();
for(int i=x.length()-1;i>=0;i–)
{
ch=x.charAt(i);
if(ch==’ ‘)
return ct;
if(Character.isLetter(ch) || ((int)(ch)>=48 && (int)(ch)<=57))
//if(ch!=’ ')
ct++;
if(i==0)
return ct;

    }
    return 0;
}

}