Java solution with Ascii,


  • 0
    Z
    public class Solution {
        public boolean detectCapitalUse(String word) {
            String low_word = word.toLowerCase();
            int len = word.length();
            int rs = 0;
            for(int i = 0; i<len; i++){
                rs += (low_word.charAt(i) - word.charAt(i));
            }
            if(rs == 0) return true;
            if(rs % 32 == 0){
                if(rs / 32 == len)  return true;
                if(rs == 32 && (low_word.charAt(0) - word.charAt(0) == 32))   return true;
            }
            return false;
        }
    }
    

Log in to reply
 

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