Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 725 Bytes

Question_2405.md

File metadata and controls

30 lines (25 loc) · 725 Bytes

LeetCode Records - Question 2405 Optimal Partition of String

Attempt 1: Use a boolean[] to record the characters in a new string

class Solution {
    public int partitionString(String s) {
        boolean[] checked = new boolean[26];
        int count = 1;

        for (char ch : s.toCharArray()) {
            if (!checked[ch - 'a']) {
                checked[ch - 'a'] = true;
                continue;
            }

            count++;
            for (int i = 0; i < 26; i++) {
                checked[i] = false;
            }
            checked[ch - 'a'] = true;
        }

        return count;
    }
}
  • Runtime: 6 ms (Beats: 95.59%)
  • Memory: 45.32 MB (Beats: 49.16%)