Skip to content

Commit 31c5753

Browse files
author
李钊
committed
✨ feat: backup
1 parent 4048632 commit 31c5753

File tree

6 files changed

+111
-5
lines changed

6 files changed

+111
-5
lines changed

1152.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class Solution
3030
};
3131
map<tuple<string, string, string>, info> hash;
3232
iota(idx.begin(), idx.end(), 0);
33-
3433
// Sort Time O(log(n))
3534
stable_sort(idx.begin(), idx.end(), [&time](int a, int b) { return time[a] < time[b]; });
3635
/*

1442.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
class Solution
6+
{
7+
public:
8+
int countTriplets(vector<int> &arr) {
9+
int n = arr.size();
10+
vector<int> prefix(n + 1, 0);
11+
for (int i = 0; i < n; ++i) {
12+
prefix[i + 1] = prefix[i] ^ arr[i];
13+
}
14+
15+
16+
17+
18+
}
19+
};

1829.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
class Solution
6+
{
7+
public:
8+
vector<int> getMaximumXor(vector<int> &nums, int maximumBit) {
9+
int n = nums.size();
10+
int acc = nums[0];
11+
const int mask = (1 << maximumBit) - 1;
12+
vector<int> ret(n, 0);
13+
for (int i = 0; i < n; ++i) {
14+
acc ^= i > 0 ? nums[i] : 0;
15+
ret[n - 1 - i] = mask ^ acc;
16+
}
17+
return ret;
18+
}
19+
};

2392.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <string>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
class Solution
7+
{
8+
public:
9+
int garbageCollection(vector<string> &garbage, vector<int> &travel) {
10+
int sum = 0, n = garbage.size();
11+
int gaps[3] = {0};
12+
int acc = 0;
13+
for (int i = 0; i < n; ++i) {
14+
acc += i > 0 ? travel[i - 1] : 0;
15+
sum += garbage[i].size();
16+
bool found[3] = {false};
17+
18+
for (auto c : garbage[i]) {
19+
if (c == 'M') {
20+
gaps[0] = acc;
21+
found[0] = true;
22+
continue;
23+
}
24+
if (c == 'G') {
25+
gaps[1] = acc;
26+
found[1] = true;
27+
continue;
28+
}
29+
30+
if (c == 'P') {
31+
gaps[2] = acc;
32+
found[2] = true;
33+
continue;
34+
}
35+
36+
if (found[0] && found[1] && found[2])
37+
break;
38+
}
39+
}
40+
41+
return sum + gaps[0] + gaps[1] + gaps[2];
42+
}
43+
};

799.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
class Solution {
6+
public:
7+
double champagneTower(int poured, int query_row, int query_glass) {
8+
vector<int> dp;
9+
int sum = 0;
10+
for (auto i = 0; i < query_row; i++) {
11+
// Fill
12+
if (i == 0) {
13+
dp.push_back(1);
14+
sum += 1;
15+
}
16+
17+
// Judge
18+
if (poured < sum) {
19+
return 0.0;
20+
}
21+
}
22+
}
23+
};

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
# C++ Weapons
1818

1919

20-
## upper_bound
2120

22-
return the first element that is less than the provided value.
21+
| Function | Method | |
22+
| :---------------------------------- | :--------------- | :---: |
23+
| Reverse a vector | std::reverse | |
24+
| First element less than provided | std::upper_bound | |
25+
| First element greater than provided | std::lower_bound | |
26+
| Find string/characterin string | std::string.find | |
27+
| | | |
2328

24-
25-
## sort

0 commit comments

Comments
 (0)