【每日刷题】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 hash[20] = {0};

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

{

hash[x] = 1;

}

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

{

if(hash[i]==0)

ans = i;

}

printf("%d",ans);

return 0;

}

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

//思路:哈希表。

int main()

{

char s[1001] = {0};

int count = 0;

char c = 0;

int hash[1001] = {0};

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

{

s[count++] = c;//获取字符串

}

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

{

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

}

char ans[1001] = {0};

int n = 0;

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

{

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

{

ans[n++] = s[i];

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

}

}

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

{

printf("%c",ans[i]);

}

return 0;

}

相关推荐
Tiandaren14 分钟前
Selenium 4 教程:自动化 WebDriver 管理与 Cookie 提取 || 用于解决chromedriver版本不匹配问题
selenium·测试工具·算法·自动化
岁忧1 小时前
(LeetCode 面试经典 150 题 ) 11. 盛最多水的容器 (贪心+双指针)
java·c++·算法·leetcode·面试·go
chao_7891 小时前
二分查找篇——搜索旋转排序数组【LeetCode】两次二分查找
开发语言·数据结构·python·算法·leetcode
秋说3 小时前
【PTA数据结构 | C语言版】一元多项式求导
c语言·数据结构·算法
Maybyy3 小时前
力扣61.旋转链表
算法·leetcode·链表
谭林杰4 小时前
B树和B+树
数据结构·b树
暮鹤筠4 小时前
[C语言初阶]操作符
c语言·开发语言
卡卡卡卡罗特5 小时前
每日mysql
数据结构·算法
chao_7896 小时前
二分查找篇——搜索旋转排序数组【LeetCode】一次二分查找
数据结构·python·算法·leetcode·二分查找
lifallen7 小时前
Paimon 原子提交实现
java·大数据·数据结构·数据库·后端·算法