Skip to content

Commit 43fd3c3

Browse files
authored
Create can-make-palindrome-from-substring.py
1 parent aa1455a commit 43fd3c3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: Python/can-make-palindrome-from-substring.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(m + n), m is the number of queries, n is the length of s
2+
# Space: O(n)
3+
4+
import itertools
5+
6+
7+
class Solution(object):
8+
def canMakePaliQueries(self, s, queries):
9+
"""
10+
:type s: str
11+
:type queries: List[List[int]]
12+
:rtype: List[bool]
13+
"""
14+
CHARSET_SIZE = 26
15+
curr, count = [0]*CHARSET_SIZE, [[0]*CHARSET_SIZE]
16+
for c in s:
17+
curr[ord(c)-ord('a')] += 1
18+
count.append(curr[:])
19+
return [sum((b-a)%2 for a, b in itertools.izip(count[left], count[right+1]))//2 <= k
20+
for left, right, k in queries]

0 commit comments

Comments
 (0)