0
0

More than 1 year has passed since last update.

難易度

Easy

アプローチ

Brute-Force

class Solution {
    public boolean detectCapitalUse(String word) {
        boolean check = false;
        for (char a : word.toCharArray()) {
            if (65 <= a && a <= 90) {
                check = true;
            } else {
                check = false;
                break;
            }
        }
        if (check) {
            return true;
        }

        for (char a : word.toCharArray()) {
            if (97 <= a && a <= 122) {
                check = true;
            } else {
                check = false;
                break;
            }
        }

        if (check) {
            return true;
        }

        int index = 0;

        for (char a : word.toCharArray()) {
            if (index == 0 && 65 <= a && a <= 90) {
                check = true;
            } else {
                if(65 <= a && a <= 90){
                    check = false;
                    break;
                }

            }
            index++;
        }

        return check;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0