/**
* // This is the interface that allows for creating nested lists.
* // You should not implement it, or speculate about its implementation
* class NestedInteger {
* public:
* // Return true if this NestedInteger holds a single integer, rather than a nested list.
* bool isInteger() const;
*
* // Return the single integer that this NestedInteger holds, if it holds a single integer
* // The result is undefined if this NestedInteger holds a nested list
* int getInteger() const;
*
* // Return the nested list that this NestedInteger holds, if it holds a nested list
* // The result is undefined if this NestedInteger holds a single integer
* const vector<NestedInteger> &getList() const;
* };
*/
class NestedIterator {
public:
vector<int>seq;int cnt =0;NestedIterator(vector<NestedInteger>&nestedList){dfs(nestedList);}voiddfs(vector<NestedInteger>&nestedList){for(auto&l : nestedList){if(l.isInteger()) seq.push_back(l.getInteger());elsedfs(l.getList());}}intnext(){return seq[cnt ++];}
bool hasNext(){return cnt < seq.size();}};/**
* Your NestedIterator object will be instantiated and called as such:
* NestedIterator i(nestedList);
* while (i.hasNext()) cout << i.next();
*/
class Solution {
public:
bool isPowerOfFour(int num){if(num <=0)return false;int t =sqrt(num);return t * t == num &&((1<<30)% num)==0;}};
class Solution {
public:intintegerBreak(int n){if(n <=3)return n -1;int res =1;if(n %3==1) res =4, n -=4;if(n %3==2) res =2, n -=2;while(n) res *=3, n-=3;return res;}};
class Solution {
public:voidreverseString(vector<char>& s){for(int i =0, j = s.size()-1; i < j; i ++, j --)swap(s[i], s[j]);}};
class Solution {
public:
string reverseVowels(string s){char vowels[]={'a','e','i','o','u'};
unordered_set<char> S;for(auto c : vowels){
S.insert(c);
S.insert(c -32);// a 97 A 65}for(int i =0, j = s.size()-1; i < j;){while(i < j &&!S.count(s[i])) i ++;while(i < j &&!S.count(s[j])) j --;if(i < j)swap(s[i], s[j]);
i ++, j --;}return s;}};
class Solution {
public:
vector<int>topKFrequent(vector<int>& nums,int k){
unordered_map<int,int>hash;for(auto x : nums) hash[x]++;//for(auto p : hash) cout << p.first << '=' << p.second << endl;int n = nums.size();
vector<int>s(n +1,0);//s[0, 1, 1, 1]for(auto p : hash) s[p.second]++;int i = n, t =0;while(t < k) t += s[i--];
vector<int> res;for(auto p : hash)if(p.second > i)
res.push_back(p.first);return res;}};
class Solution {
public:
vector<int>intersection(vector<int>& nums1, vector<int>& nums2){
unordered_set<int>set(nums1.begin(), nums1.end());
vector<int> res;for(int i =0; i < nums2.size(); i ++)if(set.find(nums2[i])!= set.end()){
res.push_back(nums2[i]);
set.erase(nums2[i]);}return res;}};
class Solution {
public:
vector<int>intersect(vector<int>& nums1, vector<int>& nums2){if(nums1.size()> nums2.size())returnintersect(nums2, nums1);
unordered_multiset<int> hash;//有重复元素for(auto x : nums1) hash.insert(x);
vector<int> res;for(auto x : nums2){if(hash.count(x)){
res.push_back(x);
hash.erase(hash.find(x));}}return res;}};
/** * // This is the interface that allows for creating nested lists. * // You should not implement it, or speculate about its implementation * class NestedInteger { * public: * // Return ...