Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0fc1a5c

Browse files
authored
Merge pull requestneetcode-gh#3660 from derekjtong/main
Create 2405-optimal-partition-of-string.cpp
2 parentsedcf7be +4df5fb5 commit0fc1a5c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎cpp/2405-optimal-partition-of-string.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
classSolution {
22
public:
3+
intpartitionString(string s) {
4+
vector<int>lastSeen(26, -1);
5+
int count =1, substringStart =0;
6+
7+
for (int i =0; i < s.length(); i++) {
8+
if (lastSeen[s[i] -'a'] >= substringStart) {
9+
count++;
10+
substringStart = i;
11+
}
12+
lastSeen[s[i] -'a'] = i;
13+
}
14+
15+
return count;
16+
}
17+
};
18+
19+
20+
classSolution {
21+
public:
322
intminPartitions(std::string s) {
423
// Set to keep track of characters in the current substring
524
std::unordered_set<char> currentChars;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp