Skip to content

Commit 09b172d

Browse files
committed
leetcode: added 977,1750
1 parent 9c59e6b commit 09b172d

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll;
6+
const ll INF = 1e18;
7+
const ll mod1 = 1e9 + 7;
8+
const ll mod2 = 998244353;
9+
// Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
int minimumLength(string s)
15+
{
16+
int left = 0, right = s.size() - 1;
17+
18+
while ((left < right) and s[left] == s[right])
19+
{
20+
char ch = s[left];
21+
while ((left <= right) and s[left] == ch)
22+
{
23+
left += 1;
24+
}
25+
while ((right >= left) and s[right] == ch)
26+
{
27+
right -= 1;
28+
}
29+
}
30+
return right - left + 1;
31+
}
32+
};

Diff for: LeetCode/977.Squares_of_a_Sorted_Array.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
vector<int> sortedSquares(vector<int> &nums)
15+
{
16+
int n=nums.size();
17+
vector<int> ans(n);
18+
int first=0,second = n-1;
19+
for(int i=n-1;i>=0;i--){
20+
if(abs(nums[first])>=abs(nums[second])){
21+
ans[i]=nums[first]*nums[first];
22+
first++;
23+
}
24+
else{
25+
ans[i]=nums[second]*nums[second];
26+
second--;
27+
}
28+
}
29+
return ans;
30+
}
31+
};

0 commit comments

Comments
 (0)