-
Notifications
You must be signed in to change notification settings - Fork 2
/
ex9.cpp
155 lines (134 loc) · 3.03 KB
/
ex9.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include"stdfx.h"
int reverse23(int x){
long long r = 0;
long long t = x;
t = t > 0 ? t : -t;
for (; t; t /= 10)
r = r * 10 + t % 10;
bool sign = x > 0 ? false : true;
if (r > INT_MAX || (sign&&r > INT_MAX)){
return 0;
}
else{
if (sign){
return -r;
}
else{
return r;
}
}
}
bool isPalindrome23(int x){
if (x < 0)
return false;
int d = 1;
while (x / d <= 10){
d *= 10;
}
while (x > 0){
int q = x / d;
int r = x % 10;
if (q != r)return false;
x = x%d / 10;
d /= 100;
}
return true;
}
struct Interval
{
int start;
int end;
Interval() :start(0), end(0){}
Interval(int s, int e) :start(s), end(e){}
};
vector<Interval> insert23(vector<Interval> &intervals, Interval newInterval){
auto iter = intervals.begin();
while (iter!=intervals.end())
{
if (newInterval.end < iter->start){
intervals.insert(iter, newInterval);
return intervals;
}
else if (newInterval.start > iter->end){
++iter;
continue;
}
else{
newInterval.start = min(newInterval.start, iter->start);
newInterval.end = max(newInterval.end, iter->end);
iter = intervals.erase(iter);
}
}
intervals.insert(intervals.end(), newInterval);
return intervals;
}
vector<Interval>insert24(vector<Interval>&intervals, Interval newInterval){
auto iter = intervals.begin();
while (iter!=intervals.end())
{
if (newInterval.end < iter->start){
intervals.insert(iter, newInterval);
return intervals;
}
else if (newInterval.start > iter->end){
++iter;
continue;
}
else{
newInterval.start = min(newInterval.start, iter->start);
newInterval.end = max(newInterval.end, iter->end);
iter = intervals.erase(iter);
}
}
intervals.insert(intervals.end(), newInterval);
return intervals;
}
vector<Interval>merge24(vector<Interval> &intervals, Interval newInterval){
vector<Interval>resultss;
for (int i = 0; i < intervals.size(); ++i){
insert24(resultss, intervals[i]);
}
return resultss;
}
string minWindow(string S, string T){
if (S.empty())return "";
if (S.size() < T.size())return "";
const int maxASCII = 256;
int aC[maxASCII];
int eC[maxASCII];
fill(aC, aC + maxASCII, 0);
fill(eC, eC + maxASCII, 0);
for (int i = 0; i < T.size(); ++i)
eC[T[i]]++;
int minWidth = INT_MAX, minStart = 0;
int wndStart = 0, app = 0;
for (int wndEnd = 0; wndEnd < S.size(); ++wndEnd){
if (eC[S[wndEnd]] > 0){
aC[S[wndEnd]]++;
if (aC[S[wndEnd]] <= eC[S[wndEnd]])
++app;
}
if (app == T.size()){
while (aC[S[wndStart]] > eC[S[wndStart]]
||eC[S[wndStart]]==0){
aC[S[wndStart]]--;
wndStart++;
}
if (minWidth > (wndEnd - wndStart + 1)){
minWidth = wndEnd - wndStart + 1;
minStart = wndStart;
}
}
}
}
int main(){
vector<int> ttb(100, 0);
ttb = {0,1,2,3,4,5,6,7,8,9};
vector<int>::iterator iter = ttb.begin();
++iter;
iter = ttb.erase(iter);
cout << *iter << endl;
for (auto its : ttb){
cout << its << " ";
}
}