3528. Unit Conversion I Medium
1/**
2 * [3528] Unit Conversion I
3 *
4 * There are n types of units indexed from 0 to n - 1. You are given a 2D integer array conversions of length n - 1, where conversions[i] = [sourceUniti, targetUniti, conversionFactori]. This indicates that a single unit of type sourceUniti is equivalent to conversionFactori units of type targetUniti.
5 * Return an array baseUnitConversion of length n, where baseUnitConversion[i] is the number of units of type i equivalent to a single unit of type 0. Since the answer may be large, return each baseUnitConversion[i] modulo 10^9 + 7.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">conversions = [[0,1,2],[1,2,3]]</span>
10 * Output: <span class="example-io">[1,2,6]</span>
11 * Explanation:
12 *
13 * Convert a single unit of type 0 into 2 units of type 1 using conversions[0].
14 * Convert a single unit of type 0 into 6 units of type 2 using conversions[0], then conversions[1].
15 * <img alt="" src="https://assets.leetcode.com/uploads/2025/03/12/example1.png" style="width: 545px; height: 118px;" /></div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">conversions = [[0,1,2],[0,2,3],[1,3,4],[1,4,5],[2,5,2],[4,6,3],[5,7,4]]</span>
19 * Output: <span class="example-io">[1,2,3,8,10,6,30,24]</span>
20 * Explanation:
21 *
22 * Convert a single unit of type 0 into 2 units of type 1 using conversions[0].
23 * Convert a single unit of type 0 into 3 units of type 2 using conversions[1].
24 * Convert a single unit of type 0 into 8 units of type 3 using conversions[0], then conversions[2].
25 * Convert a single unit of type 0 into 10 units of type 4 using conversions[0], then conversions[3].
26 * Convert a single unit of type 0 into 6 units of type 5 using conversions[1], then conversions[4].
27 * Convert a single unit of type 0 into 30 units of type 6 using conversions[0], conversions[3], then conversions[5].
28 * Convert a single unit of type 0 into 24 units of type 7 using conversions[1], conversions[4], then conversions[6].
29 * </div>
30 *
31 * Constraints:
32 *
33 * 2 <= n <= 10^5
34 * conversions.length == n - 1
35 * 0 <= sourceUniti, targetUniti < n
36 * 1 <= conversionFactori <= 10^9
37 * It is guaranteed that unit 0 can be converted into any other unit through a unique combination of conversions without using any conversions in the opposite direction.
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/unit-conversion-i/
43// discuss: https://leetcode.com/problems/unit-conversion-i/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn base_unit_conversions(conversions: Vec<Vec<i32>>) -> Vec<i32> {
49 vec![]
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_3528() {
61 }
62}
63Back
© 2026 bowen.ge All Rights Reserved.