From 582533f5105667b95ad142b16c8cf09a610d0f7b Mon Sep 17 00:00:00 2001 From: utkarsh-7 Date: Sat, 31 Oct 2020 02:11:18 +0530 Subject: [PATCH 1/2] Added Problem 3 and 42 in cpp --- C++/Solution#3.cpp | 46 ++++++++++++++++++++++++++++++++++++ C++/Solution#42.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 C++/Solution#3.cpp create mode 100644 C++/Solution#42.cpp 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 From b2c2aeaf0e9079e069e3c40cf90e9371458963ae Mon Sep 17 00:00:00 2001 From: utkarsh-7 Date: Sat, 31 Oct 2020 02:19:51 +0530 Subject: [PATCH 2/2] Updated Contributions.md --- Contributors.md | 2 ++ 1 file changed, 2 insertions(+) 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) +