头像

kidforever911




离线:2小时前


最近来访(241)
用户头像
xiongmao
用户头像
遇到坎就得迈过去
用户头像
拒绝emo
用户头像
violet_garden
用户头像
TonyJiang
用户头像
@Dong
用户头像
寂寞无语
用户头像
Mooncnc
用户头像
yxc的小迷妹
用户头像
mzx
用户头像
KK_9
用户头像
ShenHanFeng
用户头像
Bug-Free
用户头像
wantongxue
用户头像
xy999
用户头像
转身ゝ未来
用户头像
aixc
用户头像
一口吃个月亮
用户头像
对方正在输入..._93
用户头像
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();
 */