Current streak:
0 days
Longest streak:
7 days
Less
More
#include<vector>
void mergeTwoSortedArraysWithoutExtraSpace(vector<long long> &nums1, vector<long long> &nums2){
// Write your code here.
int i=nums1.size()-1;
int j=0;
while(i>=0 && j<nums2.size()){
if(nums1[i]>nums2[j]){
swap(nums1[i], nums2[j]);
i--;
j++;
}
else{
break;
}
}
sort(nums1.begin(), nums1.end());
sort(nums2.begin(), nums2.end());
// j=nums2.size();
}
#include <bits/stdio.h>
#include <bits/stdc++.h>
bool isAnagram(string str1, string str2)
{
//Write your code here
sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());
if(str1!=str2){
return 0;
}
return 1;
}
int lowestCommonAncestor(TreeNode<int> *root, int x, int y)
{
// Write your code here
if(root==NULL){
return -1;
}
if(root->data==x || root->data==y){
return root->data;
}
int leftchild=lowestCommonAncestor(root->left, x, y);
int rightchild=lowestCommonAncestor(root->right, x, y);
if(leftchild==-1 && rightchild==-1){
return -1;
}
if(leftchild!=-1 && rightchild==-1){
return leftchild;
}
if(leftchild==-1 && rightchild!=-1){
return rightchild;
}
if(leftchild!=-1 && rightchild!=-1){
return root->data;
}
}
int lowestCommonAncestor(TreeNode<int> *root, int x, int y)
{
// Write your code here
if(root==NULL){
return -1;
}
if(root->data==x || root->data==y){
return root->data;
}
int leftchild=lowestCommonAncestor(root->left, x, y);
int rightchild=lowestCommonAncestor(root->right, x, y);
if(leftchild==-1 && rightchild==-1){
return -1;
}
if(leftchild!=-1 && rightchild==-1){
return leftchild;
}
if(leftchild==-1 && rightchild!=-1){
return rightchild;
}
if(leftchild!=-1 && rightchild!=-1){
return root->data;
}
}