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 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 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<