Skip to content

Commit b8d5182

Browse files
committed
done adding 255 question solution
1 parent 85aa209 commit b8d5182

File tree

255 files changed

+6849
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+6849
-0
lines changed

01.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
vector<int> twoSum(vector<int>& nums, int target){
4+
for(int i=0;i<nums.size()-1;i++){
5+
for(int j=i+1;j<nums.size();j++){
6+
if(nums[i]+nums[j]==target){
7+
return {i,j};
8+
}
9+
}
10+
}
11+
return {};
12+
}
13+
14+
int main(){
15+
vector<int> nums({2,7,10,15});
16+
twoSum(nums,9);
17+
return 0;
18+
}
19+
// this code is done by mohit kumar

100.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include<bits/stdc++.h>
2+
/*some of the ide does not support the upper include so the below code is important*/
3+
#include<iostream>
4+
using namespace std;
5+
6+
int same(TreeNode*p , TreeNode*q){
7+
if(!p && !q){
8+
return true;
9+
}
10+
if(p && q && p->val == q->val){
11+
return same(p->left,q->left) && same(p->right, q->right);
12+
}
13+
}
14+
15+
int main()
16+
{
17+
return 0;
18+
}

1002.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include<bits/stdc++.h>
2+
#include<iostream>
3+
4+
using namespace std;
5+
6+
int main()
7+
{
8+
cout<<"hello world"<<endl;
9+
return 0;
10+
}

1002.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# // print the common word in the list
2+
# leetcode dialy challenge
3+
def common(words):
4+
res = []
5+
for char in set(words[0]):
6+
# here we are including the minimum occurance of the character
7+
# like if b is not present in the third word then it min occurance will be 0
8+
res += char*min([word.count(char) for word in words])
9+
print(res)
10+
lst=["bella","label","roller"]
11+
common(lst)
12+
13+
14+

1004.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
class Solution{
5+
public:
6+
int longestOnes(vector<int> & nums, int k){
7+
int left=0,right=0;
8+
int maxlen = 0;
9+
int zeros=0;
10+
int len = 0;
11+
while(right<nums.size()){
12+
if(nums[right]==0){zeros++;}
13+
if(zeros>k){
14+
if(nums[left]==0){
15+
zeros--;
16+
}
17+
left++;
18+
}
19+
if(zeros<=k){
20+
len = right-left+1;
21+
maxlen = max(len , maxlen);
22+
}
23+
right ++;
24+
}
25+
return maxlen;
26+
27+
}
28+
}
29+
30+
int main(){
31+
return 0;
32+
}
33+

1004_another.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int longestOnes(vector<int> &nums, int k) {
5+
int left = 0, right = 0, count = k, maxLen = 0;
6+
7+
while (right < nums.size()) {
8+
if (nums[right] == 0) {
9+
if (count > 0) {
10+
count--;
11+
right++;
12+
} else {
13+
maxLen = max(maxLen, right - left);
14+
while (nums[left] == 1) {
15+
left++;
16+
}
17+
left++;
18+
right++;
19+
}
20+
} else {
21+
right++;
22+
}
23+
return max(maxLen, right - left);
24+
}
25+
}
26+
27+
int main() { return 0; }

1008.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
TreeNode* bstFromPreorder(vector<int>& preorder){
5+
int index = 0;
6+
return helper(preorder, index, INT_MAX);
7+
}
8+
TreeNode* helper(vector<int>& preorder, int& index, int bound){
9+
if(index>=preorder.size() || preorder[index]>bound){
10+
return nullptr;
11+
}
12+
int rootVal = preorder[index++];
13+
TreeNode* node = new TreeNode(rootVal);
14+
node->left = helper(preorder, index, rootVal);
15+
node->right = helper(preorder,index, bound);
16+
return node;
17+
}
18+
19+
20+
int main()
21+
{
22+
return 0;
23+
}

101.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
class Solution {
6+
public:
7+
bool isSymmetric(TreeNode* root) {
8+
if(root==NULL) return true;
9+
return mirror(root->left, root->right);
10+
}
11+
bool mirror(TreeNode* left, TreeNode* right){
12+
if(left==nullptr && right==nullptr){
13+
return true;
14+
}
15+
if(left==nullptr || right==nullptr){
16+
return false;
17+
}
18+
return (left->val == right->val) && mirror(left->left, right->right) && mirror(left->right, right->left);
19+
}
20+
21+
};
22+
23+
int main()
24+
{
25+
return 0;
26+
}

102.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
vector<vector<int>> levelorder(TreeNode* root){
5+
vector<vector<int>> ans;
6+
if(root==NULL){
7+
return ans;
8+
}
9+
queue<TreeNode*> q;
10+
q.push(root);
11+
while(!q.empty()){
12+
int size= q.size();
13+
vector<int> level;
14+
for(int i =0;i<size;i++){
15+
TreeNode* temp = q.front();
16+
q.pop();
17+
level.push_back(temp->val);
18+
if(temp->left!=NULL){
19+
q.push(temp->left);
20+
}
21+
if(temp->right!=NULL){
22+
q.push(temp->right);
23+
}
24+
}
25+
ans.push_back(level);
26+
}
27+
return ans;
28+
}
29+
30+
int main()
31+
{
32+
return 0;
33+
}

103.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
vector<vector<int>> zigzagLevelOrder(TreeNode* root){
5+
vector<vector<int>> res;
6+
if(root == nullptr){
7+
return ans;
8+
}
9+
queue<TreeNode*> q;
10+
q.push(root);
11+
while(!q.empty()){
12+
int s = q.size();
13+
vector<int> level;
14+
for(int i = 0;i<s;i++){
15+
TreeNode* node = q.front();
16+
q.pop();
17+
level.push_back(node->val);
18+
if(node->left){
19+
q.push(node->left);
20+
}
21+
if(node->right){
22+
q.push(node->right);
23+
}
24+
}
25+
if(ans.size()%2){
26+
reverse(level.begin(), level.end());
27+
}
28+
ans.push_back(level);
29+
}
30+
}
31+
32+
int main()
33+
{
34+
return 0;
35+
}

0 commit comments

Comments
 (0)