old/Algorithm Solving
LeetCode 2469. Convert the Temperature 자바 문제 풀이
은색거북이
2023. 7. 22. 23:00
반응형
문제
Convert the Temperature - LeetCode
문제 해결 방법
- double 어레이를 선언하고 맞는 수를 입력할수 있는지 물어보는 문제입니다.
Github Link
https://github.com/eunhanlee/LeetCode_2469_ConverttheTemperature_Solution
시간복잡도: O(1), 공간복잡도: O(1)
public class Solution {
/**
* Converts a temperature value from Celsius to Kelvin and Fahrenheit.
*
* @param celsius the temperature value in Celsius
* @return an array containing the converted temperature values in Kelvin and Fahrenheit,
* where the first element is the Kelvin value and the second element is the Fahrenheit value
*/
public double[] convertTemperature(double celsius) {
// Kelvin = Celsius + 273.15
// Fahrenheit = Celsius * 1.80 + 32.00
double[] result = new double[2];
result[0] = celsius + 273.15;
result[1] = celsius * 1.80 + 32.00;
return result;
}
}
class Solution {
public double[] convertTemperature(double celsius) {
return new double[]{celsius+273.15 , (celsius*1.80+32.00)};
}
}
반응형