We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3df0940 commit 1f12369Copy full SHA for 1f12369
longest-substring-without-repeating-characters/mike2ox.cpp
@@ -0,0 +1,27 @@
1
+/**
2
+ * https://leetcode.com/problems/longest-substring-without-repeating-characters/
3
+ * 풀이방법: Sliding Window
4
+ *
5
+ * 공간 복잡도: O(1)
6
+ * 시간 복잡도: O(n)
7
+ */
8
+
9
+#include <vector>
10
11
+class Solution {
12
+public:
13
+ int lengthOfLongestSubstring(string s) {
14
+ int answer = 0;
15
+ vector<int> visit(256, -1);
16
+ int i, j;
17
18
+ for (i = 0, j = 0; i < s.size(); i++){
19
+ if (visit[s[i]] != -1 && visit[s[i]] >= j && visit[s[i]] < i) {
20
+ j = visit[s[i]] + 1;
21
+ }
22
+ answer = max(answer, i - j + 1);
23
+ visit[s[i]] = i;
24
25
+ return answer;
26
27
+};
0 commit comments