leetcode---Power of Two---lower_bound,upper_bound,binary_search
来源:互联网 发布:环迅网络兼职是真的吗 编辑:程序博客网 时间:2024/06/05 05:55
Given an integer, write a function to determine if it is a power of two.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
class Solution {public: vector<int> powTwo; bool isPowerOfTwo(int n) { vector<int> powTwo; int i; for(i=0; i<31; i++) { int a = (1 << i); powTwo.push_back(a); } vector<int>::iterator l, r; l = lower_bound(powTwo.begin(), powTwo.end(), n); r = upper_bound(powTwo.begin(), powTwo.end(), n); if(l == r-1) return true; else return false; }};
class Solution {public: vector<int> powTwo; bool isPowerOfTwo(int n) { vector<int> powTwo; int i; for(i=0; i<31; i++) { int a = (1 << i); powTwo.push_back(a); } int m = binary_search(powTwo.begin(), powTwo.end(), n); if(m == 1) return true; else return false; }};
0 0
- leetcode---Power of Two---lower_bound,upper_bound,binary_search
- count、find、binary_search、lower_bound、upper_bound
- STL之lower_bound()、upper_bound()、binary_search
- STL:lower_bound & upper_bound & binary_search (UVaOJ 146)
- 二分查找—lower_bound 、upper_bound 、binary_search
- STL中的二分查找--lower_bound/upper_bound/binary_search
- STL之二分查找(binary_search(),lower_bound(),upper_bound() )
- STL之sort(),binary_search(),lower_bound(),upper_bound()函数
- STL之二分查找(binary_search(),lower_bound(),upper_bound() )
- STL之二分查找(binary_search(),lower_bound(),upper_bound() )
- STL之二分查找(binary_search(),lower_bound(),upper_bound() )
- STL 二分查找(binary_search(),lower_bound(),upper_bound() )
- [LeetCode] Power of Two
- 【LeetCode】Power of Two
- [Leetcode]Power of Two
- [leetCode] Power of Two
- leetcode --Power of Two
- leetcode: Power of Two
- (4)
- 对任意随机10个数求和(1)
- 什么是面向对象分析OOA?
- Ruby On Rails--Layouts and Rendering in Rails(布局和页面渲染)
- android数据存储——SharedPreferencs
- leetcode---Power of Two---lower_bound,upper_bound,binary_search
- 随机十个数求和4
- 100天JAVA学习计划04-认识封装
- 重装jdk时出错Error: could not open `C:\Program Files\Java\jre6\lib\amd64\jvm.cfg'
- 转载_用Doxygen+Graphviz生成函数调用流程图 转
- mybait的文件配置
- 异常处理
- 如何用SQL命令查看Mysql数据库大小
- Ruby On Rails--Action View Form Helpers(页面表单帮助方法)