2469. Convert the Temperature LeetCode Solution
In this guide, you will get 2469. Convert the Temperature LeetCode Solution with the best time and space complexity. The solution to Convert the Temperature problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Convert the Temperature solution in C++
- Convert the Temperature solution in Java
- Convert the Temperature solution in Python
- Additional Resources
Problem Statement of Convert the Temperature
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].
Return the array ans. Answers within 10-5 of the actual answer will be accepted.
Note that:
Kelvin = Celsius + 273.15
Fahrenheit = Celsius * 1.80 + 32.00
Example 1:
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.
Example 2:
Input: celsius = 122.11
Output: [395.26000,251.79800]
Explanation: Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.
Constraints:
0 <= celsius <= 1000
Complexity Analysis
- Time Complexity: O(1)
- Space Complexity: O(1)
2469. Convert the Temperature LeetCode Solution in C++
class Solution {
public:
vector<double> convertTemperature(double celsius) {
return {celsius + 273.15, celsius * 1.8 + 32};
}
};
/* code provided by PROGIEZ */
2469. Convert the Temperature LeetCode Solution in Java
class Solution {
public double[] convertTemperature(double celsius) {
return new double[] {celsius + 273.15, celsius * 1.8 + 32};
}
}
// code provided by PROGIEZ
2469. Convert the Temperature LeetCode Solution in Python
class Solution:
def convertTemperature(self, celsius: float) -> list[float]:
return [celsius + 273.15, celsius * 1.8 + 32]
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.