about | help | code help+videos | done | prefs |
fastPower
Define a recursive function that when passed two integers (say x and n), returns x to the power of n. You should think of how to make it faster to avoid time-outs and/or StackOverflowErrors. You may not use any loops. For brownie points, write a theoretically tail-optimized version (since Java doesn't really facilitate tail-optimization... yet). Use the hint only if you have spent sufficient time thinking and are still stuck. fastPower(1, 10000) → 1 fastPower(0, 200000) → 0 fastPower(2, 30) → 1073741824 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 3 Post-solution available
Copyright Nick Parlante 2017 - privacy