Skip to content

Commit 6a8ff33

Browse files
committed
1333
1 parent aad06d9 commit 6a8ff33

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

1332.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int removePalindromeSub(string s) {
4+
if(s.length()==0){
5+
return 0;
6+
}
7+
int n=s.length()-1;
8+
int i=0;
9+
bool a=true;
10+
while(i<n){
11+
if(s[i++]!=s[n--]){
12+
a=false;
13+
break;
14+
}
15+
}
16+
if(a){
17+
return 1;
18+
}
19+
else {
20+
return 2;
21+
}
22+
}
23+
};

1333.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
static bool cmp(const vector<int>& v1, const vector<int>& v2) {
2+
return v1[1] == v2[1] ? v1[0] > v2[0] : v1[1] > v2[1];
3+
}
4+
5+
class Solution {
6+
public:
7+
vector<int> filterRestaurants(vector<vector<int>>& restaurant, int veganFriendly, int maxPrice, int maxDistance) {
8+
9+
int n=restaurant.size();
10+
vector<vector<int>>result;
11+
12+
if(veganFriendly==1)
13+
{
14+
for(int i=0;i<n;i++)
15+
{
16+
if(restaurant[i][2]==1)
17+
{
18+
if(restaurant[i][3]<=maxPrice)
19+
{
20+
if(restaurant[i][4]<=maxDistance)
21+
{
22+
result.push_back(restaurant[i]);
23+
}
24+
}
25+
}
26+
}
27+
28+
}
29+
30+
if(veganFriendly==0)
31+
{
32+
for(int i=0;i<n;i++)
33+
{
34+
if(restaurant[i][3]<=maxPrice)
35+
{
36+
if(restaurant[i][4]<=maxDistance)
37+
{
38+
result.push_back(restaurant[i]);
39+
}
40+
}
41+
}
42+
43+
}
44+
45+
sort(result.begin(),result.end(),cmp) ;
46+
47+
vector<int>ids;
48+
for(int i=0;i<result.size();i++)
49+
{
50+
ids.push_back(result[i][0]);
51+
}
52+
53+
return ids;
54+
55+
}
56+
};

0 commit comments

Comments
 (0)