⬆︎
×

[LC] 3270 Find the Key of the Numbers

Hyplus目录

Java

/**
 * <a href="https://leetcode.cn/problems/find-the-key-of-the-numbers/">Find the Key of the Numbers</a>
 * 数学
 */
class Solution {
    public int generateKey(int num1, int num2, int num3) {
        int key = 0;
        for (int p = 1; num1 > 0 && num2 > 0 && num3 > 0; p *= 10) {
            key += Math.min(Math.min(num1 % 10, num2 % 10), num3 % 10) * p;
            num1 /= 10;
            num2 /= 10;
            num3 /= 10;
        }
        return key;
    }
}

Go

func generateKey(num1 int, num2 int, num3 int) int {
    key := 0
    for p := 1; num1 > 0 && num2 > 0 && num3 > 0; p *= 10 {
        key += min(num1%10, num2%10, num3%10) * p
        num1 /= 10
        num2 /= 10
        num3 /= 10
    }
    return key
}

发表评论