initial commit
This commit is contained in:
commit
e8bc10fd75
31
551.cpp
Normal file
31
551.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
class Solution
|
||||
{
|
||||
public:
|
||||
bool checkRecord(string s)
|
||||
{
|
||||
int absent_count = 0;
|
||||
for (int i = 0; i < s.length(); i++)
|
||||
{
|
||||
absent_count += (s[i] == 'A');
|
||||
if (absent_count > 1)
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < (int)s.length() - 2; i++)
|
||||
{
|
||||
// cout<<i<<" "<<s[i]<<endl;
|
||||
if (s[i] == 'A' && s[i] == s[i + 1] && s[i + 1] == s[i + 2])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Solution s;
|
||||
cout<<s.checkRecord("A")<<endl;
|
||||
return 0;
|
||||
}
|
42
888.cpp
Normal file
42
888.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution
|
||||
{
|
||||
public:
|
||||
int sum(vector<int> &A)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < A.size(); i++)
|
||||
sum += A[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
vector<int> fairCandySwap(vector<int> &A, vector<int> &B)
|
||||
{
|
||||
int diff = (sum(A) - sum(B))/2;
|
||||
cout<<diff<<endl;
|
||||
for (int i = 0; i < A.size(); i++)
|
||||
for (int j = 0; j < B.size(); j++)
|
||||
if ((A[i] - B[j]) == diff)
|
||||
return vector<int>{A[i], B[j]};
|
||||
return vector<int>{0, 0};
|
||||
}
|
||||
};
|
||||
|
||||
void outputVector(vector<int> A)
|
||||
{
|
||||
for (int i = 0; i < A.size(); i++)
|
||||
cout<<A[i]<<" ";
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
vector<int> A = {2};
|
||||
vector<int> B = {1, 3};
|
||||
Solution solution = Solution();
|
||||
outputVector(solution.fairCandySwap(A, B));
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user