class Solution {
public:int hundred =100, thousand =1000, million =1000000, billion =1000000000;
unordered_map<int, string>numbers;
string numberToWords(int num){char number20[][30]={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};char number2[][20]={"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};for(int i =0; i <20; i ++) numbers[i]= number20[i];for(int i =20, j =0; i <100; i +=10, j ++) numbers[i]= number2[j];
numbers[hundred]="Hundred", numbers[thousand]="Thousand";
numbers[million]="Million", numbers[billion]="Billion";
string res;for(int k =1000000000; k >=100; k /=1000){if(num >= k){
res +=' '+get3(num / k)+' '+ numbers[k];
num %= k;}}if(num) res +=' '+get3(num);if(res.empty()) res =' '+ numbers[0];return res.substr(1);}
string get3(int num){
string res;if(num >= hundred){
res +=' '+ numbers[num / hundred]+' '+ numbers[hundred];
num %= hundred;}if(num){if(num <20) res +=' '+ numbers[num];elseif(num %10==0) res +=' '+ numbers[num];else res +=' '+ numbers[num /10*10]+' '+ numbers[num %10];}return res.substr(1);}};
class Solution {
public:inthIndex(vector<int>& citations){sort(citations.begin(), citations.end());int res =0;for(int i =0; i < citations.size(); i ++)if(citations.size()- i <= citations[i]){
res = citations.size()- i;break;}return res;}};
class Solution {
public:inthIndex(vector<int>& citations){if(citations.empty())return0;int l =0, r = citations.size()-1;while(l < r){int mid = l + r >>1;if(citations.size()- mid <= citations[mid]) r = mid;else l = mid +1;}if(citations.size()- l <= citations[l])return citations.size()- l;return0;}};
// Forward declaration of isBadVersion API.
bool isBadVersion(int version);
class Solution {
public:intfirstBadVersion(int n){int l =1, r = n;while(l < r){int mid = l +0ll+ r >>1;if(isBadVersion(mid)) r = mid;else l = mid +1;}return l;}};
class Solution {
public:intnumSquares(int n){
vector<int>f(n +1, n);
f[0]=0;for(int i =1; i <= n; i ++)for(int j =1; j * j <= i; j ++)
f[i]=min(f[i], f[i - j * j]+1);return f[n];}};