My simple 0ms Java Solution


  • 0
    V

    '''
    public int lengthOfLastWord(String s) {

    	if(s == null) {
    		return 0;
    	}
    	
    	s = s.trim();
    	
    	int result = 0;
    	int len = 0;
    	
    	for(int i = s.length()-1; i >= 0;i--) {
    		len++;
    		if(s.charAt(i) == ' ') {
    		    len--;
    			break;
    		}
    	}
    	
    	return len;
    
    }
    

    '''


Log in to reply
 

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