Skip to content

Commit 9d3a9b2

Browse files
authored
Merge pull request #670 from adherent9870/newm
first missing positve integer
2 parents 9eb845d + 53eee42 commit 9d3a9b2

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

LeetCode/containerwithmostwater.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "bits/stdc++.h"
2+
using namespace std;
3+
int maxArea(int height[],int n)
4+
{
5+
int i,j;
6+
7+
i=0;
8+
j=n-1;
9+
int area = INT_MIN;
10+
while(i<j)
11+
{
12+
area = max(area,min(height[i],height[j])*(j-i));
13+
if(height[j]>height[i])
14+
{
15+
i++;
16+
}
17+
else
18+
{
19+
j--;
20+
}
21+
}
22+
return area;
23+
}
24+
int main(){
25+
int n;
26+
cin >>n;
27+
int nums[n];
28+
for(int i=0; i<n; i++){
29+
cin >> nums[i] ;
30+
}
31+
int res=maxArea(nums,n);
32+
cout<< res <<endl;
33+
return 0;
34+
}

LeetCode/firstmissinginteger.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
using namespace std;
3+
int first(int nums[],int n) {
4+
for (int j = 0; j < n - 1; j++){
5+
if (nums[j] > nums[j + 1]){
6+
int temp = nums[j];
7+
nums[j] = nums[j + 1];
8+
nums[j + 1] = temp;
9+
j = -1;
10+
}
11+
}
12+
int z=1;
13+
for(int i=0; i<n; i++){
14+
if(nums[i]==z){z++;}
15+
}
16+
return z;
17+
}
18+
int main(){
19+
int n;
20+
cin >>n;
21+
int nums[n];
22+
for(int i=0; i<n; i++){
23+
cin >> nums[i] ;
24+
}
25+
int res=first(nums,n);
26+
cout<< res <<endl;
27+
return 0;
28+
}

0 commit comments

Comments
 (0)