File tree Expand file tree Collapse file tree 4 files changed +51
-1
lines changed
3556. Sum of Largest Prime Substrings
3557. Find Maximum Number of Non Intersecting Substrings Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ };
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments