当前位置:网站首页>11.1-CM24 最近公共祖先
11.1-CM24 最近公共祖先
2022-08-02 15:35:00 【syc596】
11.1-CM24 最近公共祖先
最近公共祖先_牛客题霸_牛客网 (nowcoder.com)
//最近公共祖先LCA
//根节点编号为1
//返回a,b最近公共祖先的编号
//a,b也是节点编号
import java.util.*;
public class LCA {
public int getLCA(int a, int b) {
while(a!=b){
if(a>b){
a/=2;
}else{
b/=2;
}
}
return a;
}
}
边栏推荐
猜你喜欢
机械臂速成小指南(十七):直线规划
Brute-force cracking of the latest JVM interview questions of Meituan: unlimited execution
2022年值得尝试的7个MQTT客户端工具
System delay tasks and scheduled tasks
24、wpf之布局(二)
20 Lectures on Disassembly of Multi-merchant Mall System Functions-Platform Distribution Overview
.NET性能优化-使用SourceGenerator-Logger记录日志
机械臂速成小指南(十四):多项式插值轨迹规划
【[NOI2001] 炮兵阵地】【状压DP】
2.4 - 三态模型
随机推荐
WWW'22 推荐系统论文之多任务与对比学习篇
CefSharp practical demonstration
ROS人机交互软件
uWSGI看这几篇就够了
Alibaba "MySQL Growth Manual" Lite Edition
ROS 之 KUKA iiwa编程
推荐系统相关顶会整理
ICML/ICLR'22 推荐系统论文梳理
【[SCOI2005] 互不侵犯】【状压DP(含概念讲解)】
JZ4 二维数组中的查找
Linux系统中mysql数据库的基本管理
制胜精细化运营时代 华为应用市场打出内容、场景、商业运营组合拳
Anti-shake throttling (continue to update later)
再见Attention:建模用户长期兴趣的新范式
#yyds干货盘点# 面试必刷TOP101: 删除链表的倒数第n个节点
【Transformer专题】Vision Transformer(ViT)原理 + 代码
23、wpf之布局(一)
Qt | 文件操作 QFile
UnicodeEncodeError: 'gbk' codec can't encode character '\u2022' in position 178: illegal multibyte s
JZ15 二进制中1的个数