From 16d840cc45c76f44175a60eb6e782f25bd49fd5b Mon Sep 17 00:00:00 2001 From: Rostislav Kuratch Date: Sun, 22 May 2022 00:56:39 +0300 Subject: [PATCH] "Longest Duplicate Substring" hard task No 1044 not accepted yet, slight speed boost --- 1044-longest-duplicate-substring.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/1044-longest-duplicate-substring.go b/1044-longest-duplicate-substring.go index a94a27a..4400b3f 100644 --- a/1044-longest-duplicate-substring.go +++ b/1044-longest-duplicate-substring.go @@ -214,8 +214,9 @@ func LongestDupSubstringSmartforceMark3Goroutine(s string, from int, to int) str return "" } - indicesNext := []int{} - indicesAll := []int{} + indicesNext := make([]int, 0, len(s)) + indicesAll := make([]int, 0, len(s)) + indicesEmpty := make([]int, 0, len(s)) for j := 0; j < strLen; j++ { indicesAll = append(indicesAll, j) @@ -243,7 +244,7 @@ func LongestDupSubstringSmartforceMark3Goroutine(s string, from int, to int) str } indicesCurrent = indicesNext - indicesNext = []int{} + indicesNext = indicesEmpty } }