✅ [Rust] 0 ms, no HashMap, simply use position differences (with detailed comments)
This solution employs simple calculation of position differences for repeated characters. It demonstrated 0 ms runtime (100.00%) and used 2.1 MB memory (97.34%)
This [solution](https://leetcode.com/submissions/detail/801296870/) employs simple calculation of position differences for repeated characters. It demonstrated **0 ms runtime (100.00%)** and used **2.1 MB memory (97.34%)**. Detailed comments are provided.\n\n**IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n```\nimpl Solution \n{\n    pub fn length_of_longest_substring(s: String) -> i32 \n    {\n        let mut max_len: usize = 0;\n        \n        // [1] longest substring is the one with the largest\n        //     difference of positions of repeated characters;\n        //     thus, we should create a storage for such positions\n        let mut pos: [usize;128] = [0;128];\n        \n        // [2] while iterating through the string (i.e., moving\n        //     the end of the sliding window), we should also\n        //     update the start of the window\n        let mut start: usize = 0;\n        \n        for (end, ch) in s.chars().enumerate()\n        {\n            // [3] get the position for the start of sliding window\n            //     with no other occurences of \'ch\' in it\n            start = start.max(pos[ch as usize]);\n            \n            // [4] update maximum length \n            max_len = max_len.max(end-start+1);\n            \n            // [5] set the position to be used in [3] on next iterations\n            pos[ch as usize] = end + 1;\n        }\n                \n        return max_len as i32;\n    }\n}\n```
['Rust']