Skip to content

Conversation

@akmhmgc
Copy link
Owner

@akmhmgc akmhmgc commented Oct 3, 2025

解いた問題

50. Pow(x, n)

使用言語

Ruby

次に解く問題

https://leetcode.com/problems/k-th-symbol-in-grammar/

@akmhmgc akmhmgc added the ruby label Oct 3, 2025
if exponent.even?
return my_pow(base, exponent / 2) ** 2
else
return base * my_pow(base, exponent - 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

趣味の範囲ですが、
return base * my_pow(base, exponent / 2) ** 2
としても良いかなと思いました。

else
result /= calculate_my_pow.call(exsp_left)
result /= calculate_my_pow.call(exsp_right)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文脈によっては二項演算子の左右を lhs, rhs と書くと伝わることがあると思いました。その場合は *= ではなく
result = calculate_my_pow.call(exsp_left) * calculate_my_pow.call(exsp_right)
と書いたらわかりやすそうです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants