diff --git a/cpp/2405-optimal-partition-of-string.cpp b/cpp/2405-optimal-partition-of-string.cpp index 3a37ecdae..4cb8b0a88 100644 --- a/cpp/2405-optimal-partition-of-string.cpp +++ b/cpp/2405-optimal-partition-of-string.cpp @@ -1,5 +1,24 @@ class Solution { public: + int partitionString(string s) { + vector lastSeen(26, -1); + int count = 1, substringStart = 0; + + for (int i = 0; i < s.length(); i++) { + if (lastSeen[s[i] - 'a'] >= substringStart) { + count++; + substringStart = i; + } + lastSeen[s[i] - 'a'] = i; + } + + return count; + } +}; + + +class Solution { + public: int minPartitions(std::string s) { // Set to keep track of characters in the current substring std::unordered_set currentChars; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy