kidforever911

3.9万

xiongmao

violet_garden
TonyJiang
@Dong

Mooncnc
yxc的小迷妹
mzx
KK_9
ShenHanFeng
Bug-Free
wantongxue
xy999

aixc

easy-money

class Solution {
public:
string findLongestWord(string s, vector<string>& dictionary) {
string result;
for(auto& temp : dictionary) {
if(check(temp, s)) {
if(result.empty() || result.size() < temp.size() || result.size() == temp.size() && result > temp) {
result = temp;
}
}
}
return result;
}

bool check(string& a, string& b) {
int i = 0, j = 0;
for( ;i < a.size() && j < b.size(); ) {
if(a[i] == b[j]) i ++;
j ++;
}
return i == a.size();
}
};

class Solution {
public:
string findLongestWord(string s, vector<string>& dictionary) {
string result;
for(auto& temp : dictionary) {
if(check(temp, s)) {
if(result.empty() || result.size() < temp.size() || result.size() == temp.size() && result > temp) {
result = temp;
}
}
}
return result;
}

bool check(string& a, string& b) {
int i = 0, j = 0;
for( ;i < a.size() && j < b.size(); ) {
if(a[i] == b[j]) i ++;
j ++;
}
return i == a.size();
}
};

class Solution {
public:
int findLUSlength(vector<string>& strs) {
int result = -1;
if(strs.empty()) return result;
int n = strs.size();
for(int i = 0; i < n; i ++) {
bool is_sub = false;
for(int j = 0; j < n; j ++) {
if(i != j && check(strs[i], strs[j])) {
is_sub = true;
break;
}
}
if(!is_sub) result = max(result, (int)(strs[i].size()));
}
return result;
}

bool check(string& a, string& b) {
int index = 0;
for(auto& c : b) {
if(c == a[index]) {
index ++;
}
}
return index == a.size();
}
};

class Solution {
public:
int findLUSlength(vector<string>& strs) {
int result = -1;
if(strs.empty()) return result;
int n = strs.size();
for(int i = 0; i < n; i ++) {
bool is_sub = false;
for(int j = 0; j < n; j ++) {
if(i != j && check(strs[i], strs[j])) {
is_sub = true;
break;
}
}
if(!is_sub) result = max(result, (int)(strs[i].size()));
}
return result;
}

bool check(string& a, string& b) {
int index = 0;
for(auto& c : b) {
if(c == a[index]) {
index ++;
}
}
return index == a.size();
}
};

class Solution {
public:
int findLUSlength(string a, string b) {
if(a == b) return -1;
return max(a.size(), b.size());
}
};

class Solution {
public:
int findLUSlength(string a, string b) {
if(a == b) return -1;
return max(a.size(), b.size());
}
};

class Solution {
public:
bool detectCapitalUse(string word) {
if(word.empty()) return false;
int s = 0;
for(auto& c : word) s += check(c);
return s == word.size() || !s || s == 1 && check(word[0]);
}

bool check(char& c) {
if(c >= 'A' && c <= 'Z') return true;
return false;
}
};

class Solution {
public:
bool detectCapitalUse(string word) {
if(word.empty()) return false;
int s = 0;
for(auto& c : word) s += check(c);
return s == word.size() || !s || s == 1 && check(word[0]);
}

bool check(char& c) {
if(c >= 'A' && c <= 'Z') return true;
return false;
}
};

class Solution {
public:
int row, col, k;
//hashmap的key是已经标记为1的位置，value是还未标记为1的位置
unordered_map<int, int> record;

Solution(int m, int n) {
row = m, col = n;
k = row * col;
}

vector<int> flip() {
int x = rand() % k;
int y = x;
if(record.count(x)) y = record[x];
if(record.count(k - 1)) {
record[x] = record[k - 1];
record.erase(k - 1);
} else record[x] = k - 1;
k --;
return {y / col, y % col};
}

void reset() {
record.clear();
k = row * col;
}
};

/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(m, n);
* vector<int> param_1 = obj->flip();
* obj->reset();
*/

class Solution {
public:
int row, col, k;
//hashmap的key是已经标记为1的位置，value是还未标记为1的位置
unordered_map<int, int> record;

Solution(int m, int n) {
row = m, col = n;
k = row * col;
}

vector<int> flip() {
int x = rand() % k;
int y = x;
if(record.count(x)) y = record[x];
if(record.count(k - 1)) {
record[x] = record[k - 1];
record.erase(k - 1);
} else record[x] = k - 1;
k --;
return {y / col, y % col};
}

void reset() {
record.clear();
k = row * col;
}
};

/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(m, n);
* vector<int> param_1 = obj->flip();
* obj->reset();
*/