class Solution {
public:
bool canWinNim(int n){return n &3;//n % 4 等价于 n & 3}};
class MedianFinder {
public:
priority_queue<int> smaller;//小根堆存储大于等于当前中位数//且小根堆的大小永远都比大根堆大1或相等
priority_queue<int, vector<int>, greater<int>> larger;//大根堆存储小于当前中位数/** initialize your data structure here. */MedianFinder(){}voidaddNum(int num){if(smaller.empty()|| num <= smaller.top())
smaller.push(num);else
larger.push(num);if(smaller.size()== larger.size()+2){int top = smaller.top();
smaller.pop();
larger.push(top);}elseif(smaller.size()+1== larger.size()){int top = larger.top();
larger.pop();
smaller.push(top);}}doublefindMedian(){if(smaller.size()== larger.size())return(smaller.top()+ larger.top())/2.0;return smaller.top();}};/**
* Your MedianFinder object will be instantiated and called as such:
* MedianFinder* obj = new MedianFinder();
* obj->addNum(num);
* double param_2 = obj->findMedian();
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Codec {
public:voiddfs(TreeNode *root, string &s){if(!root){
s +=',';return;}
s +=to_string(root->val)+',';dfs(root->left, s);dfs(root->right, s);}// Encodes a tree to a single string.
string serialize(TreeNode* root){
string s ="";dfs(root, s);return s;}
TreeNode *decode(int&cur,const string &data){if(data[cur]==','){
cur ++;returnNULL;}int nxt = data.find(',', cur);int val =stoi(data.substr(cur, nxt - cur));
TreeNode *r = new TreeNode(val);
cur = nxt +1;
r->left =decode(cur, data);
r->right =decode(cur, data);return r;}// Decodes your encoded data to tree.
TreeNode*deserialize(string data){int cur =0;returndecode(cur, data);}};// Your Codec object will be instantiated and called as such:// Codec codec;// codec.deserialize(codec.serialize(root));
class Solution {
public:
string getHint(string secret, string guess){int n = secret.size(), bulls =0, cows =0;
vector<int>vis(10,0);for(int i =0; i < n; i ++){
vis[secret[i]-'0']++;if(secret[i]== guess[i])
bulls ++;}for(int i =0; i < n; i ++){if(vis[guess[i]-'0']>0){
cows ++;
vis[guess[i]-'0']--;}}returnto_string(bulls)+"A"+to_string(cows - bulls)+"B";}};
class Solution {
public:intlengthOfLIS(vector<int>& nums){if(nums.size()==0)return0;
vector<int>dp(nums.size(),1);int res =1;for(int i =1; i < nums.size(); i ++){for(int j =0; j < i; j ++)if(nums[i]> nums[j])
dp[i]=max(dp[i], dp[j]+1);if(dp[i]> res)
res = dp[i];}return res;}};
class Solution {
public:intlengthOfLIS(vector<int>& nums){int tt =0;
vector<int>q(nums.size());for(auto x : nums){if(!tt || x > q[tt -1]) q[tt ++]= x;else{int l =0, r = tt -1;while(l < r){int mid = l + r >>1;if(q[mid]>= x) r = mid;else l = mid +1;}
q[l]= x;}}return tt;}};
class Solution {public: bool canWinNim(int n) { return n & 3; //n % 4 等价于 n & 3 }};class MedianFinder {public: priority_queue<int> smaller;//小根堆存储大于等于当前中位数 ...