Skip to content

Commit 00f23e9

Browse files
committed
exercise/id3
1 parent 7ec6e1b commit 00f23e9

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev)
1717

1818
[//]: # (- [Linked List](#linked-list))
1919

20-
[//]: # (- [String](#string))
20+
- [String](#string)
2121

2222
[//]: # (- [Binary Tree](#binary-tree))
2323

@@ -55,7 +55,13 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev)
5555
| 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy |
5656
| 283 | [Move Zeroes](src/main/kotlin/exercise/easy/id283/Description283.md) | [solution](src/main/kotlin/exercise/easy/id283/Solution283.kt) | [test](src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy |
5757
| 977 | [Squares of a Sorted Array](src/main/kotlin/exercise/easy/id977/Description977.md) | [solution](src/main/kotlin/exercise/easy/id977/Solution977.kt) | [test](src/test/kotlin/exercise/easy/id977/Solution977Test.kt) | Easy |
58-
| 57 | [Insert Internal](src/main/kotlin/exercise/medium/id57/Description57.md) | [solution](src/main/kotlin/exercise/medium/id57/Solution57.kt) | [test](src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium |
58+
| 57 | [Insert Internal](src/main/kotlin/exercise/medium/id57/Description57.md) | [solution](src/main/kotlin/exercise/medium/id57/Solution57.kt) | [test](src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium |
59+
60+
#### String
61+
62+
| ID | Description | Solution | Test | Difficulty |
63+
|:--:|:------------------------------------------------------------------------------------------------------|:------------------------------------------------------------:|:------------------------------------------------------------:|:----------:|
64+
| 3 | [Longest Substring Without Repeating Characters](src/main/kotlin/exercise/medium/id3/Description3.md) | [solution](src/main/kotlin/exercise/medium/id3/Solution3.kt) | [test](src/test/kotlin/exercise/medium/id3/Solution3Test.kt) | Medium |
5965

6066
[//]: # (https://www.techinterviewhandbook.org/grind75?weeks=26&hours=40&grouping=topics)
6167

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT)
2+
3+
# Longest Substring Without Repeating Characters
4+
5+
![Difficulty](https://img.shields.io/badge/Difficulty-Medium-548af7)
6+
7+
Given a string `s`, find the length of the longest substring without repeating characters.
8+
9+
Example 1:
10+
11+
```
12+
Input: s = "abcabcbb"
13+
Output: 3
14+
```
15+
16+
Example 2:
17+
18+
```
19+
Input: s = "bbbbb"
20+
Output: 1
21+
Explanation: The answer is `b`, with the length of 1.
22+
```
23+
24+
Example 3:
25+
26+
```
27+
Input: s = "pwwkew"
28+
Output: 3
29+
Explanation: The answer is `wke`, with the length of 3.
30+
Notice that the answer must be a substring, `pwke` is a subsequence and not a substring.
31+
```
32+
33+
Constraints:
34+
35+
- `0 <= s.length <= 5 * 10^4`
36+
- `s` consists of English letters, digits, symbols and spaces.
37+
38+
| ID | Description | Solution | Test | Difficulty |
39+
|:--:|:-----------------------------------------------|:--------------------------:|:------------------------------------------------------------------------------:|:----------:|
40+
| 3 | Longest Substring Without Repeating Characters | [solution](./Solution3.kt) | [test](../../../../../../src/test/kotlin/exercise/medium/id3/Solution3Test.kt) | Medium |
41+
42+
:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package exercise.medium.id3
2+
3+
4+
class Solution3 {
5+
fun lengthOfLongestSubstring(s: String): Int {
6+
7+
var longest: String
8+
9+
return 0
10+
}
11+
12+
/*
13+
14+
15+
16+
*/
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package exercise.medium.id3
2+
3+
import io.kotest.assertions.print.print
4+
import io.kotest.core.spec.style.FunSpec
5+
import io.kotest.datatest.withData
6+
import io.kotest.matchers.shouldBe
7+
8+
data class TestCase(val s: String, val expected: Int)
9+
10+
class Solution3Test : FunSpec({
11+
12+
context(name = "shouldBe") {
13+
withData(
14+
nameFn = { "s: ${it.s.print().value}, expected: ${it.expected.print().value}" },
15+
TestCase("abcabcbb", expected = 3),
16+
TestCase("bbbbb", expected = 1),
17+
TestCase("pwwkew", expected = 3),
18+
) { (s, expected) ->
19+
Solution3().lengthOfLongestSubstring(s) shouldBe expected
20+
}
21+
}
22+
})

0 commit comments

Comments
 (0)