diff --git a/C++/Solution#3.cpp b/C++/Solution#3.cpp new file mode 100644 index 0000000..6f41765 --- /dev/null +++ b/C++/Solution#3.cpp @@ -0,0 +1,46 @@ +/* +3. Longest Substring Without Repeating Characters +Medium + + +Given a string s, find the length of the longest substring without repeating characters. + + + +Example 1: + +Input: s = "abcabcbb" +Output: 3 +Explanation: The answer is "abc", with the length of 3. +Example 2: + +Input: s = "bbbbb" +Output: 1 +Explanation: The answer is "b", with the length of 1. + +*/ + +class Solution { +public: + int lengthOfLongestSubstring(string s) { + int beg=0; + int end=0; + unsigned long int len=0; + set st; + while(end& height) { + if(height.size()==0) + return 0; + int i,pi=0,wt=0,s=(int)(height.size()-1),tp=0; + int p=height[0]; + for(i=1;i<=s;i++) + { + if(height[i]>p) + { + pi=i; + p=height[i]; + tp=0; + } + else + { + wt+=p-height[i]; + tp+=p-height[i]; + } + } + if(pi=pi;i--) + { + if(height[i] >= p) + { + p = height[i]; + } + else + { + wt += p - height[i]; + } + } + } + return wt; + } +}; \ No newline at end of file diff --git a/Contributors.md b/Contributors.md index efcf8ce..3f8c58f 100644 --- a/Contributors.md +++ b/Contributors.md @@ -29,3 +29,5 @@ **Caitlin Genna** --> "CS Computer Science Graduate, Fordham University." --> [caitlingenna](https://github.com/caitlingenna) +**Utkarsh Nigam** --> "Learner | C.S undergrad" --> [utkarsh-7](https://github.com/utkarsh-7) +