Skip to content

Commit

Permalink
✨ Brute force solution for problem 003
Browse files Browse the repository at this point in the history
  • Loading branch information
jobearrr committed Jul 10, 2024
1 parent a2714b8 commit 4631714
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// LongestSubstringWithoutRepeatingCharactersBruteForceSolution.swift
// LeetSwift
//
// Created by Jobert on 10/07/2024.
//

import Core
import Foundation
import Problems

final class LongestSubstringWithoutRepeatingCharactersBruteForceSolution: LongestSubstringWithoutRepeatingCharactersDefinition {

func lengthOfLongestSubstring(_ s: String) -> Int {
let chars = Array(s)
var maxLength = 0

for i in 0..<chars.count {
var seen = Set<Character>()
for j in i..<chars.count {
if seen.contains(chars[j]) {
break
}
seen.insert(chars[j])
maxLength = max(maxLength, j - i + 1)
}
}

return maxLength
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import XCTest

final class LongestSubstringWithoutRepeatingCharactersSolutionTests: XCTestCase {

let solution: LongestSubstringWithoutRepeatingCharactersDefinition = LongestSubstringWithoutRepeatingCharactersSolution()
let solution: LongestSubstringWithoutRepeatingCharactersDefinition = LongestSubstringWithoutRepeatingCharactersBruteForceSolution()

func testSolution() {
for testData in data {
Expand Down

0 comments on commit 4631714

Please sign in to comment.