Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 521 Bytes

Question_2351.md

File metadata and controls

24 lines (19 loc) · 521 Bytes

LeetCode Records - Question 2351 First Letter to Appear Twice

Attempt 1: Use an int[] to save the character counts

class Solution {
    public char repeatedCharacter(String s) {
        int[] counts = new int[26];

        for (char ch : s.toCharArray()) {
            counts[ch - 'a']++;

            if (counts[ch - 'a'] == 2) {
                return ch;
            }
        }

        return 0;
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 40.94 MB (Beats: 96.49%)