From 22e4fd6ec947682fb239b73f01be275b99f7dd02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jobert=20S=C3=A1?= Date: Wed, 17 Jul 2024 18:07:14 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Problem=20003=20Optimized=20Solutio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...eCharsOptimizedSlidingWindowSolution.swift | 35 +++++++++++++++++++ ...sOptimizedSlidingWindowSolutionTests.swift | 28 +++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Sources/Solutions/003 - Longest Substring Without Repeating Characters/LongestSubstringWithUniqueCharsOptimizedSlidingWindowSolution.swift create mode 100644 Tests/SolutionsTests/003 - Longest Substring Without Repeating Characters/LongestSubstringWithUniqueCharsOptimizedSlidingWindowSolutionTests.swift diff --git a/Sources/Solutions/003 - Longest Substring Without Repeating Characters/LongestSubstringWithUniqueCharsOptimizedSlidingWindowSolution.swift b/Sources/Solutions/003 - Longest Substring Without Repeating Characters/LongestSubstringWithUniqueCharsOptimizedSlidingWindowSolution.swift new file mode 100644 index 0000000..2d0d469 --- /dev/null +++ b/Sources/Solutions/003 - Longest Substring Without Repeating Characters/LongestSubstringWithUniqueCharsOptimizedSlidingWindowSolution.swift @@ -0,0 +1,35 @@ +// +// LongestSubstringWithUniqueCharsOptimizedSlidingWindowSolution.swift +// LeetSwift +// +// Created by Jobert on 10/07/2024. +// + +import Core +import Foundation +import Problems + +final class LongestSubstringWithUniqueCharsOptimizedSlidingWindowSolution: LongestSubstringWithUniqueCharsDefinition { + + func lengthOfLongestSubstring(_ s: String) -> Int { + var indexArray = Array(repeating: -1, count: 128) + var maxLength = 0 + var start = 0 + + let chars = Array(s) + + for i in 0..