diff --git a/Leetcode/CPP/2016. Maximum Difference Between Increasing Elements.cpp b/Leetcode/CPP/2016. Maximum Difference Between Increasing Elements.cpp new file mode 100644 index 00000000..add496d3 --- /dev/null +++ b/Leetcode/CPP/2016. Maximum Difference Between Increasing Elements.cpp @@ -0,0 +1,10 @@ +class Solution { +public: + int maximumDifference(vector& nums) { + int ans = -1 , mn = INT_MAX; + for(auto i : nums) + if(mn >= i) mn = i; + else ans = max(ans, i-mn); + return ans; + } +}; diff --git a/Leetcode/CPP/2032. Two Out of Three.cpp b/Leetcode/CPP/2032. Two Out of Three.cpp new file mode 100644 index 00000000..bf56f811 --- /dev/null +++ b/Leetcode/CPP/2032. Two Out of Three.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + vector twoOutOfThree(vector& nums1, vector& nums2, vector& nums3) { + set a, b, c; + for(auto i : nums1) a.insert(i); + for(auto i : nums2) b.insert(i); + for(auto i : nums3) c.insert(i); + set res; + for(auto i : a) if(b.find(i)!=b.end() || c.find(i)!=c.end()) res.insert(i); + for(auto i : b) if(c.find(i)!=c.end() || a.find(i)!=a.end()) res.insert(i); + for(auto i : c) if(a.find(i)!=a.end() || b.find(i)!=b.end()) res.insert(i); + vector ret; + for(auto i : res) ret.push_back(i); + return ret; + } +}; diff --git a/Leetcode/CPP/2042. Check if Numbers Are Ascending in a Sentence.cpp b/Leetcode/CPP/2042. Check if Numbers Are Ascending in a Sentence.cpp new file mode 100644 index 00000000..bf5d8551 --- /dev/null +++ b/Leetcode/CPP/2042. Check if Numbers Are Ascending in a Sentence.cpp @@ -0,0 +1,23 @@ +class Solution { +public: + bool areNumbersAscending(string s) { + bool res = true; + vector numbers; + int curr = -1; + s += " "; + for(auto i : s) + { + if(i<='9' && i>='0') + { + if(curr==-1) curr = 0; + curr = curr*10 + (i-'0'); + } + else if(curr!=-1) + numbers.push_back(curr) , curr = -1; + } + + for(int i = 1 ; i < numbers.size() ; i++) if(numbers[i]<=numbers[i-1]) res = false; + + return res; + } +};