Convert the Temperature — LeetCode 2469 Python Solution
- Problem
- #2469
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].
Example
- Input
- celsius = 36.50
- Output
- [309.65000,97.70000]
- Explanation
- Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.
Python solution
class Solution:
def convertTemperature(self, celsius: float) -> List[float]:
return [celsius + 273.15, celsius * 1.8 + 32]Complexity
| Measure | Complexity |
|---|---|
| Time | O(1) |
| Space | O(1) auxiliary |
Pattern: Math and Number Theory
Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 2469. Convert the Temperature is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math.
The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2469. Convert the Temperature?
- LeetCode 2469. Convert the Temperature is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2469. Convert the Temperature?
- The Python solution on this page runs in O(1).
- What is the space complexity of LeetCode 2469. Convert the Temperature?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2469. Convert the Temperature cover?
- LeetCode 2469. Convert the Temperature is tagged Math on LeetCode.