Leet Code OJ 231. Power of Two [Difficulty: Easy]
题目:
Given an integer, write a function to determine if it is a power of two.
分析:
题意是给定一个整数,判断它是不是2的幂。
代码实现:
public class Solution {public boolean isPowerOfTwo(int n) {if(n<1){return false;}if(n==1){return true;}if((n&1)==0) {return isPowerOfTwo(n/2);} else{return false;}}
}
Leet Code OJ 231. Power of Two [Difficulty: Easy]相关推荐
- Leet Code OJ 326. Power of Three [Difficulty: Easy]
题目: Given an integer, write a function to determine if it is a power of three. Follow up: Could you ...
- Leet Code OJ 14. Longest Common Prefix [Difficulty: Easy]
题目: Write a function to find the longest common prefix string amongst an array of strings. 翻译: 写一个函数 ...
- Leet Code OJ 118. Pascal's Triangle [Difficulty: Easy]
题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...
- Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy]
题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Not ...
- Leet Code OJ 110. Balanced Binary Tree [Difficulty: Easy]
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...
- Leet Code OJ 219. Contains Duplicate II [Difficulty: Easy]
题目: Given an array of integers and an integer k, find out whether there are two distinct indices i a ...
- Leet Code OJ 172. Factorial Trailing Zeroes [Difficulty: Easy]
题目: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- Leet Code OJ 206. Reverse Linked List [Difficulty: Easy]
题目: Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursiv ...
- Leet Code OJ 38. Count and Say [Difficulty: Easy]
题目: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 11 ...
最新文章
- UVA 10700 Camel trading
- Modelsim初级使用教程
- React Native 之 网络请求 fetch
- 使用ganglia监控hadoop及hbase集群
- 通过一个简单的例子学习Angular Injection Token工作原理
- Linux 手动安装Ettercap
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 职场提醒:面试失败n次以后
- 常用技巧 —— 桶排
- linux之service命令
- loading怎么关闭 vant_Vant Loading 加载
- JAVA排序:快速排序算法
- 编好的C语言程序怎么放记事本上运行,怎么用记事本运行程序
- 华为:一个中国民族企业的“下半场”在哪里?
- 【python中级】linux系统获得计算机网卡流量
- 一、深度学习和神经网络
- 论文笔记《ST-GRAT: A Novel Spatio-temporal Graph Attention Network for Accurately Forecasting》
- 区块链重要基础知识8-1——冷存储以及热存储和他们之间相互如何结合
- 通过js点击事件处理防止表单重复提交
- 网络协议:网络层传输层