Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1c340db

Browse files
committed
leetcode: add 1400
1 parent 3599f35 commit 1c340db

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
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+
bool canConstruct(string s, int k)
15+
{
16+
vector<int> v(26,0);
17+
int n = s.size();
18+
for (auto x : s)
19+
{
20+
v[x-'a']++;
21+
}
22+
int odd = 0, even = 0;
23+
for (auto x : v)
24+
{
25+
odd += (x % 2);
26+
even += (x / 2);
27+
}
28+
k-=odd;
29+
return k>=0 && k<=2*even;
30+
}
31+
};

0 commit comments

Comments
 (0)