Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 758 Bytes

Question_3120.md

File metadata and controls

32 lines (27 loc) · 758 Bytes

LeetCode Records - Question 3120 Count the Number of Special Characters I

Attempt 1: Use two boolean[]

class Solution {
    public int numberOfSpecialChars(String word) {
        boolean[] lowers = new boolean[26];
        boolean[] uppers = new boolean[26];

        for (char ch : word.toCharArray()) {
            if (ch <= 'Z') {
                uppers[ch - 'A'] = true;
            } else {
                lowers[ch - 'a'] = true;
            }
        }

        int count = 0;
        for (int i = 0; i < 26; i++) {
            if (lowers[i] && uppers[i]) {
                count++;
            }
        }

        return count;
    }
}
  • Runtime: 1 ms (Beats: 100.00%)
  • Memory: 42.04 MB (Beats: 82.00%)