Leetcode Pow (x, N) (Math, Binary Search) (*)

Source: Internet
Author: User

translation
实现pow(x, n).
Original
pow(x, n).
Analysis

First of all, we recommend Wikipedia:

zh.wikipedia.org/wiki/two Yuan search tree

En.wikipedia.org/wiki/binary_search_tree

Second, you can also look at a similar question:

Leetcode Sqrt (x) (Math, Binary Search) (*)

However, I still did not solve the problem, look at other people's solution ...

Class Solution {Private:Double Mypowhelper(DoubleXLong Long intN) {if(n==0)return 1;Else if(n==1)returnXElse if(n%2==0)        {Doubletemp = MYPOW (x, n/2);returnTemp*temp; }Else{DoubleTemp=mypow (x, (n1)/2);returnTemp*temp*x; }    } Public:Double Mypow(DoubleXintN) {Long Long intN = (Long Long intNif(n>=0)returnMypowhelper (x, N);Else            returnMypowhelper ((1.0/x),-N); }};

Pay tribute to the person who wrote the code ...

Leetcode Pow (x, N) (Math, Binary Search) (*)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.