[LeetCode]Pow(x, n)
2015-08-10 08:48
302 查看
题目
Number: 50Difficulty: Medium
Tags: Math Binary Search
Implement pow(x, n).
题解
实现幂函数。代码
[code]double myPow(double x, int n) { if( x == 1 || n == 0) return 1; double t = myPow(x, n / 2); if(n % 2) return n < 0 ? 1 / x * t * t : x * t * t; else return t * t; }
相关文章推荐
- java.lang.Object.clone()分析
- 让DIV中文字换行显示
- C++中关于new和delete的使用
- [LeetCode]Anagrams
- [LeetCode]Rotate Image
- 360等杀掉了app的主进程后 ,如何自动开启 如何防止被kill
- 设计模式:代理模式
- hdoj2159FATE【二维dp】
- iOS UI_相册
- Valid Anagram
- [LeetCode]Permutations
- 黑马程序员-----Java基础-----面向对象!
- POJ 1260 Pearls(DP)
- ABAP BAPI 和 RFC 的区别
- mongdo通用类(C#版)
- Lotto
- 内存管理
- 剑指Offer面试题39(Java版):二叉树的深度
- 强大的考勤管理
- Struts2中有关struts-default.xml,struts.xml,struts.properties文件详解