【每日刷题】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;

}

相关推荐
@蓝莓果粒茶41 分钟前
LeetCode第245题_最短单词距离III
c语言·c++·笔记·学习·算法·leetcode·c#
闻闻不会编程1 小时前
704. 二分查找 (力扣)
数据结构·算法·leetcode
AndrewHZ1 小时前
【图像处理基石】立体匹配的经典算法有哪些?
图像处理·算法·计算机视觉·滤波·模式识别·立体匹配
AndrewHZ1 小时前
【图像处理入门】4. 图像增强技术——对比度与亮度的魔法调节
图像处理·算法·计算机视觉·几何变换·图像增强·模式识别
不二狗2 小时前
每日算法 -【Swift 算法】查找字符串数组中的最长公共前缀
开发语言·算法·swift
不二狗2 小时前
每日算法 -【Swift 算法】将整数转换为罗马数字
开发语言·算法·swift
Moonbit2 小时前
双周报Vol.73:移除使用方法实现 trait 、新增了 “错误多态” 功能、.语法支持使用 _ 的匿名函数...
后端·算法
chao_7892 小时前
链表题解——反转链表【LeetCode】
开发语言·python·算法
Code_流苏3 小时前
Python趣学篇:从零打造智能AI井字棋游戏(Python + Tkinter + Minimax算法)
python·算法·游戏·tkinter·智能井字棋·minimax算法
Lu Yao_3 小时前
【数据结构 -- B树】
数据结构·b树