From 7a1e5a771bd6ef6bddb6fa07be6371b2f9175d5f Mon Sep 17 00:00:00 2001 From: Sourav Date: Wed, 14 Oct 2020 19:42:04 +0530 Subject: [PATCH 1/3] 56 Merge Intervals --- 56.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 56.cpp diff --git a/56.cpp b/56.cpp new file mode 100644 index 0000000..bb016e0 --- /dev/null +++ b/56.cpp @@ -0,0 +1,21 @@ +class Solution { +public: + vector> merge(vector>& intervals) { + vectorarr(2); + vector>ans; + if(intervals.size()==0) return ans; + sort(intervals.begin(),intervals.end()); + arr[0]=intervals[0][0];arr[1]=intervals[0][1]; + for(int i=1;i=intervals[i][0]) + arr[1]=max(intervals[i][1],arr[1]); + else + { ans.push_back({arr[0],arr[1]}); + arr[0]=intervals[i][0]; + arr[1]=intervals[i][1]; + } + } + ans.push_back({arr[0],arr[1]}); + return ans; + } +}; \ No newline at end of file From 6c4c600be5631692ebe5de3c6072aa9af2ee6bc9 Mon Sep 17 00:00:00 2001 From: Sourav Date: Wed, 14 Oct 2020 19:45:13 +0530 Subject: [PATCH 2/3] 59 --- 59.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 59.cpp diff --git a/59.cpp b/59.cpp new file mode 100644 index 0000000..f29428d --- /dev/null +++ b/59.cpp @@ -0,0 +1,35 @@ +class Solution { +public: + + vector> generateMatrix(int n) { + vector> matrix; + matrix.resize(n, std::vector(n, -1)); + + int top = 0; + int bottom = n-1; + int left = 0; + int right = n-1; + int val = 1; + while (left<=right) { + + for (int i = left;i<=right;i++) { + matrix[left][i] = val++; + } + top++; + + for (int i = top;i<=bottom;i++) { + matrix[i][right] = val++; + } + right--; + for (int i = right;i>=left;i--) { + matrix[bottom][i] = val++; + } + bottom--; + for (int i = bottom;i>=top;i--) { + matrix[i][left] = val++; + } + left++; + } + return matrix; + } +}; \ No newline at end of file From 5d60e5f688c1c13fff7b922b3858b83b8aa4295f Mon Sep 17 00:00:00 2001 From: Sourav Date: Wed, 14 Oct 2020 19:48:50 +0530 Subject: [PATCH 3/3] 60 --- 60.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 60.cpp diff --git a/60.cpp b/60.cpp new file mode 100644 index 0000000..ed28542 --- /dev/null +++ b/60.cpp @@ -0,0 +1,24 @@ +class Solution { +public: + string getPermutation(int n, int k) { + string st(n,'0'); + int fact=1; + for(int i=1;i<=n;i++){ + fact*=i; + st[i-1]+=(i); + } + for(int i=0;i=i+1;j--){ + st[j]=st[j-1]; + } + st[i]=c; + cout<