Simple straightforward Java API solution


  • 0
    S
    public boolean detectCapitalUse(String word) {
           char[] myArray = word.toCharArray();
           boolean result = false;
           if (myArray.length == 1 && !(myArray[0] >= 97) || !(myArray[0] <= 122)) {
               result = true;
           }
           if (result) {
               return result;
           }
           for (int i = 1; i < myArray.length; i++) {
               if ((myArray[0] >= 65) && (myArray[0] <= 90)) {
                   result = true;
               }
               if (myArray[i] >= 97 && myArray[i] <= 122) {
                   result = true;
               } else {
                   result = false;
                   break;
               }
           }
           if (result) {
               return result;
           }
           for (int i = 0; i < myArray.length; i++) {
               if (!(myArray[i] >= 97) || !(myArray[i] <= 122)) {
                   result = false;
                   break;
               } else {
                   result = true;
               }
           }
           if (result) {
               return result;
           }
           for (int i = 0; i < myArray.length; i++) {
               if (!(myArray[i] >= 65) || !(myArray[i] <= 90)) {
                   result = false;
                   break;
               } else {
                   result = true;
               }
           }
           return result;
       }
    

Log in to reply
 

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