-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString.cpp
More file actions
53 lines (46 loc) · 887 Bytes
/
Copy pathString.cpp
File metadata and controls
53 lines (46 loc) · 887 Bytes
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
53
#include <string>
#include <cctype>
string s;
string s="hello";
string s(5, 'a'); // aaaaa
string s="";
getline(cin, s); // to get full string
s[5];
s.front();
s.back();
s.length();
s.size();
s[i] = x;
reverse(s.begin(), s.end());
sort(s.begin(), s.end());
count(s.begin(), s.end(), 'a');
s.find("xyz");
s.substr(start, length);
s.erase(pos, length);
s.replace(pos, length, substr);
s.insert(pos, substr);
isdigit(x);
isalpha(x);
isupper(x);
islower(x);
tolower(x);
toupper(x);
// FREQUENCY
vector<int> freq
for(char c:s){
freq[c-'a']++;
}
// TWO POINTER
int l=0;
int r=s.size() - 1;
while(l<r){
. . .
// increment/ decrement accordingly (together or independent)
l++;
r--:
}
// SLIDING WINDOW
// sliding forward
new sum = old sum - left element + right element (back++ & front++)
// sliding backword
new sum = old sum + left element - right element (back-- & front--)