179. 最大数【贪心】1453. 移掉K位数字【贪心 / 思维】783. 二叉搜索树节点最小距离71. 二叉树的深度208. 实现 Trie (前缀树)【未完成】142. 前缀统计【trie】213. 打家劫舍 II【未完成】1055. 股票买卖 II【贪心】87. 扰乱字符串【未完成】94. 递归实现排列型枚举
179. 最大数【贪心】class Solution {
public:
string largestNumber(vector& nums)
{
sort(nums.begin(),nums.end(),[](int x,int y)
{
string a=to_string(x),b=to_string(y);
return a+b>b+a;
}
);
string ans;
for(int i=0;i1&&ans[0]=='0') ans=ans.substr(1);
return ans;
}
};
1453. 移掉K位数字【贪心 / 思维】
#includeusing namespace std; int k; int main(void) { string res="0"; string s; cin>>s>>k; for(int i=0;i 1&&res[0]=='0') res=res.substr(1);//去除前导零 cout< 783. 二叉搜索树节点最小距离 class Solution { public: int minDiffInBST(TreeNode* root) { vector71. 二叉树的深度ve; dfs(root,ve); sort(ve.begin(),ve.end()); int ans=1e9; for(int i=1;i & ve) { if(!root) return; ve.push_back(root->val); if(root->left) dfs(root->left,ve); if(root->right) dfs(root->right,ve); } }; class Solution { public: int ans=0; void dfs(TreeNode* root,int len) { if(!root) return; ans=max(ans,len); if(root->left) dfs(root->left,len+1); if(root->right) dfs(root->right,len+1); } int treeDepth(TreeNode* root) { dfs(root,1); return ans; } };208. 实现 Trie (前缀树)【未完成】class Trie { public: Trie() { } void insert(string word) { } bool search(string word) { } bool startsWith(string prefix) { } };142. 前缀统计【trie】#includeusing namespace std; const int N=1e6+10; int son[N][26],cnt[N],idx; void insert(string s) { int p=0; for(int i=0;i >n>>m; for(int i=0;i >s; insert(s); } while(m--) { string s; cin>>s; cout< 213. 打家劫舍 II【未完成】 1055. 股票买卖 II【贪心】 #includeusing namespace std; const int N=1e5+10; int a[N],ans,n; int main(void) { cin>>n; for(int i=0;i >a[i]; for(int i=0;i 87. 扰乱字符串【未完成】 94. 递归实现排列型枚举 #includeusing namespace std; int a[30],vis[30],n; void dfs(int index) { if(index==n) { for(int i=0;i >n; dfs(0); return 0; }



