leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

powx-n.dart (381B)


      1 //Given an input double x return x^n power without using
      2 //a built in power method.
      3 class Solution {
      4   double myPow(double x, int n) {
      5       if(n == 0){
      6         return 1;
      7       }
      8       double return_val = x;
      9       for(int i = 1; i < n.abs() ; ++i){
     10         return_val = return_val * x;
     11       }
     12       if(n < 0){
     13         return 1 / return_val;
     14       }
     15       return return_val;
     16   }
     17 }