← 返回 meta 的题目列表Pow(x, n)
类型:qbank
LeetCode 50. Fast-exponentiation `x^n` with negative-exponent handling. Classic Meta phone-screen warm-up.
Requirements
Implement pow(x, n) with n possibly negative.
O(log |n|) via iterative or recursive squaring.
Edge: n = INT_MIN (use -n carefully; cast to long or handle as a special case).
Notes
Interviewer may ask for both iterative and recursive versions.
Common bug: integer overflow when negating INT_MIN; common follow-up: pow(x, n) mod p for modular exponentiation.
Preparation
Memorize iterative squaring template.
Drill modular-pow variant (pow(x, n, p)) — appears as the natural follow-up.