【每日刷题】Day65

【每日刷题】Day65

🥕个人主页:开敲🍉

🔥所属专栏:每日刷题🍍

🌼文章目录🌼

[1. LCR 175. 计算二叉树的深度 - 力扣(LeetCode)](#1. LCR 175. 计算二叉树的深度 - 力扣(LeetCode))

[2. 序列找数_牛客题霸_牛客网 (nowcoder.com)](#2. 序列找数_牛客题霸_牛客网 (nowcoder.com))

[3. 删除重复字符_牛客题霸_牛客网 (nowcoder.com)](#3. 删除重复字符_牛客题霸_牛客网 (nowcoder.com))

1. LCR 175. 计算二叉树的深度 - 力扣(LeetCode)

//思路:分治思想+深度优先遍历。将每一个结点视为根节点,返回其左右子树较深的深度。

int _calculateDepth(struct TreeNode* root)

{

if(!root)

return 0;

int left = _calculateDepth(root->left);//计算左子树深度

int right = _calculateDepth(root->right);//计算右子树深度

return 1+(left>right?left:right);//返回更大的,同时加上自身

}

int calculateDepth(struct TreeNode* root)

{

return _calculateDepth(root);

}

2. 序列找数_牛客题霸_牛客网 (nowcoder.com)

//思路:哈希表。

int main()

{

int ans = 0;

int n = 0;

scanf("%d",&n);

int x = 0;

int hash20 = {0};

while (scanf("%d", &x) != EOF)

{

hashx = 1;

}

for(int i = 0;i<=n;i++)

{

if(hashi==0)

ans = i;

}

printf("%d",ans);

return 0;

}

3. 删除重复字符_牛客题霸_牛客网 (nowcoder.com)

//思路:哈希表。

int main()

{

char s1001 = {0};

int count = 0;

char c = 0;

int hash1001 = {0};

while(scanf("%c",&c)!=EOF)

{

scount++ = c;//获取字符串

}

for(int i = 0;i<count;i++)

{

hashs\[i-'a'] = 1;//字符-'a'的值作为key,val为1,确保之后重复出现的字符只出现一次

}

char ans1001 = {0};

int n = 0;

for(int i = 0;i<count;i++)

{

if(hashs\[i-'a'])//遍历字符串,如果其key的val为1,存入答案字符串中

{

ansn++ = si;

hashs\[i-'a'] = 0;//再将val置为0,确保重复字符只出现一次

}

}

for(int i = 0;i<n;i++)

{

printf("%c",ansi);

}

return 0;

}

相关推荐
电科_银尘12 分钟前
【大模型算法与工程 15】手写Self-Attention:Q、K、V与缩放点积
算法
郝学胜-神的一滴3 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
秋天的怀念_David3 小时前
算法一千零一夜 · 第三十三夜 · 跳表
java·程序人生·算法
戊本菌5 小时前
进程(三)进程优先级:谁先上 CPU
linux·c语言·硬件架构
Pniubi6 小时前
力扣21合并两个有序链表
算法·leetcode·职场和发展
AIgorithmGEEK7 小时前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set
上海潭龙东海科技有限公司8 小时前
智慧堆场动态模型三维实时孪生重构智能管控
大数据·网络·数据库·算法·重构
嵌入式 Linux手记9 小时前
一块内存,三种解释:union 的真实用法
linux·c语言·驱动开发·嵌入式
阿庆_AI研发工程师10 小时前
Stanford CS336 Lecture 10:大语言模型推理与性能优化
算法
用户73416810354811 小时前
基于MindSpore的深度残差收缩网络程序
算法