2 Straightforward C# Solutions w/ explanation + Sliding Window
Approach 1: Sliding Window\n\nImplementation\n\npublic int LengthOfLongestSubstring(string s) {\n\tvar letters = new Dictionary<char, int>(); // key:letter, val
### **Approach 1: Sliding Window**\n\n**Implementation**\n```\npublic int LengthOfLongestSubstring(string s) {\n\tvar letters = new Dictionary<char, int>(); // key:letter, val: latest index\n\tint maxCount = 0, left = 0, right;\n\n\tfor (right = 0; right < s?.Length; right++) {\n\t\tchar letter = s[right];\n\n\t\tif (letters.ContainsKey(letter)) { // End the window\n\t\t\tleft = Math.Max(left, letters[letter] + 1); // Update left of window\n\t\t}\n\n\t\tletters[letter] = right; //Update index of letter on map\n\n\t\tmaxCount = Math.Max(maxCount, right - left + 1); // Get the longest window length \n\t}\n\n\treturn maxCount;\n}\n```\n\n---\n\n### **Approach 2: Using a list to remember the substring length**\n*(faster than 89%, memory less than 99%) *\n\n**Algorithm**\n* Use a list `letters` to remember the substrings with unique characters\n* If a duplicate is detected,\n\t* Get the substring `length` and determine the `maxLength`\n\t* Remove the preceding characters up to the duplicate letter from the list using `RemoveRange`\n* Continue until the end \n\n**Complexity**\n* Time: `O(n)`, where `n` is the length of the string `s`\n* Space: `O(n)` since we created the list `letters` that will contain a maximum of all the letters in the entire string `s`\n\n**Implementation**\n```csharp\npublic class Solution {\n    public int LengthOfLongestSubstring(string s) {\n        List<char> letters = new List<char>();\n        int maxLength = 0;\n        \n        foreach (char c in s) {\n            if (!letters.Contains(c)) {\n                letters.Add(c);\n            }\n            else {\n                maxLength = Math.Max(maxLength, letters.Count);\n                \n                // remove preceding characters up to the duplicate letter\n                int idx = letters.IndexOf(c);\n                letters.RemoveRange(0, idx+1);\n\n                letters.Add(c);\n            }\n        }\n        \n        return Math.Max(maxLength, letters.Count); \n    }\n}\n```\n\n**If you like the solution, please upvote \uD83D\uDD3C**
['Sliding Window', 'C#']