diff --git a/Amazon/String/763-Partition_Labels.py b/Amazon/String/763-Partition_Labels.py index 94960fb..e1206ed 100644 --- a/Amazon/String/763-Partition_Labels.py +++ b/Amazon/String/763-Partition_Labels.py @@ -8,13 +8,13 @@ def partitionLabels(self, S: str) -> List[int]: start = 0 end = 0 last_indices = [None] * 26 - - for i in range(len(S)): + l=len(S) # it will be fast if once I calculate it and use multiple times. + for i in range(l) : last_indices[ord(S[i]) - ord('a')] = i - for i in range(len(S)): + for i in range(l) : end = max(end, last_indices[ord(S[i]) - ord('a')]) if end == i: output_arr.append(end - start + 1) start = end + 1 - return output_arr \ No newline at end of file + return output_arr