summaryrefslogtreecommitdiff
path: root/0003
diff options
context:
space:
mode:
Diffstat (limited to '0003')
-rw-r--r--0003/Cargo.lock7
-rw-r--r--0003/Cargo.toml6
-rw-r--r--0003/src/main.rs34
3 files changed, 47 insertions, 0 deletions
diff --git a/0003/Cargo.lock b/0003/Cargo.lock
new file mode 100644
index 0000000..86306ae
--- /dev/null
+++ b/0003/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "p3"
+version = "0.1.0"
diff --git a/0003/Cargo.toml b/0003/Cargo.toml
new file mode 100644
index 0000000..f8264b5
--- /dev/null
+++ b/0003/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "p3"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/0003/src/main.rs b/0003/src/main.rs
new file mode 100644
index 0000000..7293c13
--- /dev/null
+++ b/0003/src/main.rs
@@ -0,0 +1,34 @@
+struct Solution {}
+
+impl Solution {
+ pub fn length_of_longest_substring(s: String) -> i32 {
+ let mut set: [u8;256] = [0;256];
+ let mut i1: usize = 0;
+ let mut i2: usize = 0;
+ let mut max: i32 = 0;
+ loop {
+ if i1 >= s.len() { break; }
+ if set[s.as_bytes()[i1] as usize] == 0 {
+ set[s.as_bytes()[i1] as usize] = 1;
+ i1 = i1 + 1;
+ if i1 as i32 - i2 as i32 > max { max = i1 as i32 - i2 as i32 }
+ continue;
+ } else {
+ loop {
+ set[s.as_bytes()[i2] as usize] = 0;
+ i2 = i2 + 1;
+ if set[s.as_bytes()[i1] as usize] == 0 {
+ break;
+ } else {
+ continue;
+ }
+ }
+ }
+ }
+ max
+ }
+}
+
+fn main() {
+ println!("{:?}", Solution::length_of_longest_substring("abcabcbb".to_string()));
+} \ No newline at end of file