leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d184996d2f3e898222bc2b73d0842f8aaf3e016b
parent 7d2e76f8c8424e7edc7c34d624191c979f191047
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Tue, 23 May 2023 07:15:40 -0500

Compltede powx-n problem using dart

Diffstat:
Apowx-n/powx-n.dart | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/powx-n/powx-n.dart b/powx-n/powx-n.dart @@ -0,0 +1,17 @@ +//Given an input double x return x^n power without using +//a built in power method. +class Solution { + double myPow(double x, int n) { + if(n == 0){ + return 1; + } + double return_val = x; + for(int i = 1; i < n.abs() ; ++i){ + return_val = return_val * x; + } + if(n < 0){ + return 1 / return_val; + } + return return_val; + } +}