class Solution {
public:intminMutation(string start, string end, vector<string>& bank){if(start.empty()|| end.empty()|| bank.empty())return-1;if(find(bank.begin(), bank.end(), end)== bank.end())return-1;
vector<int>vis(bank.size(),0);int step =0;
queue<string>q;
q.push(start);while(!q.empty()){
step ++;int n = q.size();for(int i =0; i < n; i ++){
string &tmp = q.front();q.pop();for(int j =0; j < bank.size(); j ++){if(vis[j]==0){int diff =0;for(int k =0; k < tmp.size(); k ++)if(tmp[k]!= bank[j][k]) diff ++;if(diff ==1){if(bank[j]== end)return step;
vis[j]=1;
q.push(bank[j]);}}}}}return-1;}};
class Solution {
public:intcountSegments(string s){
s +=' ';int res =0;for(int i =0; i < s.size()-1; i ++)if(s[i]!=' '&& s[i +1]==' ')
res ++;return res;}};
class Solution {
public:interaseOverlapIntervals(vector<vector<int>>& intervals){sort(intervals.begin(), intervals.end(),[&](const vector<int>&i1,const vector<int>&i2){return i1[0]< i2[0];});int cnt =0;int end =-1;for(auto&i : intervals){if(end ==-1||end <= i[0])
end = i[1];elseif(end > i[0]){
cnt ++;
end =min(end, i[1]);}}return cnt;}};
class Solution {
public:
vector<int>findRightInterval(vector<vector<int>>& intervals){
map<int,int>hash;
vector<int> res;int n = intervals.size();for(int i =0; i < n; i ++)
hash[intervals[i][0]]= i;//找到一个比目标起点大的下标for(auto i : intervals){auto it = hash.lower_bound(i[1]);//hash里面是起点 找比目标终点>=的位置int min_pos = INT_MAX;if(it != hash.end())
min_pos =min(min_pos, it->second);else
min_pos =-1;
res.push_back(min_pos);}return res;}};
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:intpathSum(TreeNode* root,int sum){
vector<int>data;int res =0;dfs(root, sum, data, res);return res;}voiddfs(TreeNode* root,int sum, vector<int>&data,int&res){if(!root)return;
data.push_back(root->val);int cur =0;for(int i = data.size()-1;~i; i --){
cur += data[i];if(cur == sum) res ++;}//cout << cur << ' ';dfs(root->left, sum, data, res);dfs(root->right, sum, data, res);
data.pop_back();}};
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:intpathSum(TreeNode* root,int sum){
vector<int>data;int res =0;dfs(root, sum, data, res);return res;}voiddfs(TreeNode* root,int sum, vector<int>data,int&res){if(!root)return;
data.push_back(root->val);int cur =0;for(int i = data.size()-1;~i; i --){
cur += data[i];if(cur == sum) res ++;}//cout << cur << ' ';dfs(root->left, sum, data, res);dfs(root->right, sum, data, res);//data.pop_back();}};
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:int res =0;intpathSum(TreeNode* root,int sum){if(!root)return0;dfs(root, sum);pathSum(root->left, sum);pathSum(root->right, sum);return res;}voiddfs(TreeNode* root,int sum){if(!root)return;
sum -= root->val;if(sum ==0) res ++;dfs(root->left, sum);dfs(root->right, sum);}};
class Solution {
public:
vector<int>findAnagrams(string s, string p){
vector<int>res;int left =0, right =0;
unordered_map<char,int>needs;
unordered_map<char,int>window;for(char c : p) needs[c]++;int match =0;while(right < s.size()){char c1 = s[right];if(needs.count(c1)){
window[c1]++;if(window[c1]== needs[c1])
match ++;}
right ++;while(match == needs.size()){if(right - left == p.size())
res.push_back(left);char c2 = s[left];if(needs.count(c2)){
window[c2]--;if(window[c2]< needs[c2])
match --;}
left ++;}}return res;}};
class Solution {
public:intfindKthNumber(int n,int k){int cur =1;--k;//进入根节点while(k >0){longlong step =0, first = cur, last = cur +1;while(first <= n){
step +=min((longlong)n +1, last)- first;
first *=10;
last *=10;}if(step <= k){
cur ++;
k -= step;}else//在子树中{
cur *=10;--k;}}return cur;}};