Easy Java Solution beats 80% of the runtimes


  • 0
    E
    public class Solution {
        public int countSegments(String s) {
            int ret=0;
        	if(s.equals(" ") || s.length()==0){
                ret=0;
            }
            String str[]=s.split(" ");
            
            for(int i=0;i<str.length;i++){
            	if(str[i].length()!=0){
            		ret++;
            	}
            }
            return ret;
        }
    }
    

Log in to reply
 

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