-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScramblies.cpp
More file actions
52 lines (45 loc) · 1.18 KB
/
Scramblies.cpp
File metadata and controls
52 lines (45 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include <string>
#include<vector>
using namespace std;
bool scramble(const string& s1, const string& s2) {
vector<int> charCount(26, 0);
for (char c : s1) {
charCount[c - 'a']++;
}
for (char c : s2) {
if (charCount[c - 'a'] == 0) {
return false;
}
charCount[c - 'a']--;
}
return true;
}
int main()
{
cout << scramble("javscripts", "javascript");
return 0;
}
/*Description:
Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2,
otherwise returns false.
Notes:
Only lower case letters will be used (a-z). No punctuation or digits will be included.
Performance needs to be considered.
Examples
scramble('rkqodlw', 'world') ==> True
scramble('cedewaraaossoqqyt', 'codewars') ==> True
scramble('katas', 'steak') ==> False
Strings
Performance
Algorithms*/
// /> フ
// | n n 彡
// /`ミ_xノ
// / |
// / ヽ ノ
// │ | | |
// / ̄| | | |
// | ( ̄ヽ__ヽ_)__)
// \二つ
// ITS CAT FOR YOU