[LeetCode] Convert the Temperature

2469. 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
1
2
3
4
5
6
7
8
class Solution {
public:
vector<double> convertTemperature(double celsius) {
double k = celsius + 273.15;
double f = celsius * 1.80 + 32.00;
return {k,f};
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/13/PS/LeetCode/convert-the-temperature/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.