Is using Regex considered as cheating?


  • 0
    L
    public class Solution {
        public int lengthOfLastWord(String s) {
            String[] words = s.split("\\s+");
            if(words.length==0)
                return 0;
            return words[words.length-1].length();
        }
    }
    

    This looks too easy if Regex is allowed.


Log in to reply
 

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