Skip to content

Commit 638d2f1

Browse files
committed
leetcode 336 C
1 parent a5f3c46 commit 638d2f1

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
int solve()
10+
{
11+
int a, b;
12+
cin >> a >> b;
13+
a = abs(a);
14+
b = abs(b);
15+
int ans = 2 * min(a, b);
16+
if (a != b)
17+
{
18+
ans += 2 * (abs(b - a)) - 1;
19+
}
20+
cout << ans << endl;
21+
22+
return 0;
23+
}
24+
int main()
25+
{
26+
int testCase = 1;
27+
cin >> testCase;
28+
while (testCase--)
29+
{
30+
solve();
31+
}
32+
return 0;
33+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
long long beautifulSubarrays(vector<int> &nums)
15+
{
16+
map<int, int> seen;
17+
seen[0]++;
18+
long long ans = 0;
19+
int sum = 0;
20+
for (int v : nums)
21+
{
22+
sum ^= v;
23+
ans += seen[sum];
24+
seen[sum]++;
25+
}
26+
return ans;
27+
}
28+
};

0 commit comments

Comments
 (0)