Skip to content

Commit 63092ef

Browse files
committed
https://leetcode.cn/problems/cycle-length-queries-in-a-tree
1 parent bcafd91 commit 63092ef

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/cycle-length-queries-in-a-tree
49+
4850
https://leetcode.cn/problems/two-sum-iii-data-structure-design/
4951

5052
https://leetcode.cn/problems/minimum-adjacent-swaps-for-k-consecutive-ones
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function cycleLengthQueries(_n: number, queries: number[][]): number[] {
2+
return queries.map(([a, b]) => {
3+
let ans = 1;
4+
while (a !== b) {
5+
if (a > b) {
6+
a = a >> 1;
7+
} else {
8+
b = b >> 1;
9+
}
10+
ans++;
11+
}
12+
return ans;
13+
});
14+
}
15+
export default cycleLengthQueries;

0 commit comments

Comments
 (0)