3270. Find the Key of the Numbers
3270. Find the Key of the Numbers
Description
You are given three positive integers num1, num2, and num3.
The key of num1, num2, and num3 is defined as a four-digit number such that:
- Initially, if any number has less than four digits, it is padded with leading zeros .
- The
i^thdigit (1 <= i <= 4) of thekeyis generated by taking the smallest digit among thei^thdigits ofnum1,num2, andnum3.
Return the key of the three numbers without leading zeros (if any).
Example 1:
1 | Input: num1 = 1, num2 = 10, num3 = 1000 |
Explanation:
On padding, num1 becomes "0001", num2 becomes "0010", and num3 remains "1000".
- The
1^stdigit of thekeyismin(0, 0, 1). - The
2^nddigit of thekeyismin(0, 0, 0). - The
3^rddigit of thekeyismin(0, 1, 0). - The
4^thdigit of thekeyismin(1, 0, 0).
Hence, the key is "0000", i.e. 0.
Example 2:
1 | Input: num1 = 987, num2 = 879, num3 = 798 |
Example 3:
1 | Input: num1 = 1, num2 = 2, num3 = 3 |
Constraints:
1 <= num1, num2, num3 <= 9999
Hints/Notes
- 2024/08/27
- digits
- 0x3Fâs solution(checked)
- Biweekly Contest 138
Solution
Language: C++
1 | class Solution { |