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

Commit a6c2510

Browse files
committed
updated sub-str value
1 parent 681618d commit a6c2510

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

‎Pattern sliding window/largest_subarray_and_sum_worst_case.py‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎Pattern sliding window/longest_substr_length_of_distinct_char.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
the_str = "cbbebi"
55
k = 3
66
hash_map = {}
7-
win_start = 0
8-
max_length = 0
9-
sub_str_arr = []
7+
win_start, max_length = 0, 0
8+
sub_str_arr = ''
109
for win_end in range(len(the_str)):
1110
right_char = the_str[win_end]
1211
if right_char not in hash_map:
1312
hash_map[right_char] = 0
1413
hash_map[right_char] += 1
15-
while len(hash_map) > k: # sub_str > k
16-
sub_str_arr.append(the_str[win_start: win_end])
14+
print(f"hash_map: {hash_map}")
15+
while len(hash_map) > k: # sub_str length > k
16+
print(f"length of hash_map: {len(hash_map)}")
1717
left_char = the_str[win_start]
18+
print(f"left char: {left_char}")
1819
hash_map[left_char] -= 1
1920
if hash_map[left_char] == 0:
2021
del hash_map[left_char]
22+
print(f"new hash_map: {hash_map}")
2123
win_start += 1
2224
max_length = max(max_length, win_end - win_start + 1)
25+
sub_str_arr = the_str[win_start: win_end+1]
2326
print(f"max_length: {max_length}")
24-
result = list(filter(lambda i: len(i) == max_length, sub_str_arr))
25-
print(f"longest sub-str: {result}")
27+
print(f"longest sub-str: {sub_str_arr}")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /