Skip to content

Commit 8143a15

Browse files
committed
git
1 parent 8b9d037 commit 8143a15

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

solutions/3556. Sum of Largest Prime Substrings/3556.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Solution {
77
for (int i = 0; i < n; ++i)
88
for (int j = i + 1; j <= n; ++j) {
99
const long num = stol(s.substr(i, j - i));
10-
if (primes.count(num) == 0 && isPrime(num))
10+
if (!primes.contains(num) && isPrime(num))
1111
primes.insert(num);
1212
}
1313

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int maxSubstrings(string word) {
4+
int ans = 0;
5+
unordered_map<char, int> firstSeen;
6+
7+
for (int i = 0; i < word.length(); ++i) {
8+
const char c = word[i];
9+
if (!firstSeen.contains(c)) {
10+
firstSeen[c] = i;
11+
} else if (i - firstSeen[c] + 1 >= 4) {
12+
++ans;
13+
firstSeen.clear();
14+
}
15+
}
16+
17+
return ans;
18+
}
19+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int maxSubstrings(String word) {
3+
int ans = 0;
4+
Map<Character, Integer> firstSeen = new HashMap<>();
5+
6+
for (int i = 0; i < word.length(); ++i) {
7+
final char c = word.charAt(i);
8+
if (!firstSeen.containsKey(c)) {
9+
firstSeen.put(c, i);
10+
} else if (i - firstSeen.get(c) + 1 >= 4) {
11+
++ans;
12+
firstSeen.clear();
13+
}
14+
}
15+
16+
return ans;
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def maxSubstrings(self, word: str) -> int:
3+
ans = 0
4+
firstSeen = {}
5+
6+
for i, c in enumerate(word):
7+
if c not in firstSeen:
8+
firstSeen[c] = i
9+
elif i - firstSeen[c] + 1 >= 4:
10+
ans += 1
11+
firstSeen.clear()
12+
13+
return ans

0 commit comments

Comments
 (0)