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 do it without using any loop / recursion?
翻译:
给定一个整数,写一个函数去判断它是否是3的幂。
更进一步:你能不使用循环或者递归来完成吗?
代码:
public class Solution {public boolean isPowerOfThree(int n) {if(n<=0){return false;}while(n!=1){if(n%3!=0){return false;}else{n/=3;}}return true;}
}
Leet Code OJ 326. Power of Three [Difficulty: Easy]相关推荐
- 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的幂 ...
- 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 ...
最新文章
- 省钱方便网上手机充话费
- oracle case grouping,ORACLE GROUPING函數的使用
- python是用c写的吗-python和c语言的区别是什么
- Oracle数据库12cR2(项目实战之二):Linux系统安装Oracle12.2
- Nginx部署静态页面及引用图片有效访问的两种方式
- 剑指Offer值字符串的排列
- OSChina 周三乱弹 —— 程序员,老了会是怎么样?
- poj 1969 Count on Canton 摘规律
- android listview固定内容,Android ListView 列表分隔,条目中添加分类信息(文字,图片等)...
- 636. 函数的独占时间
- K8S学习笔记之借助Minikube完成在windows环境下Kubernetes的单节点搭建-(超级简单)
- 【有手就行】电脑蓝屏恶搞(附带一键复原方法)
- 【python】CNN算法
- H5分享带缩略图,描述,微信内分享到好友,朋友圈等
- QLabel显示QImage时报错
- 丧心病狂!最新NLP模型的写作水平已突破次元壁
- Chrome/Edge插件-在线视频画质增强,支持视频加速
- 可擦玻璃平顶的机器人_擦玻璃机器人的优点和缺点各是什么?智能擦窗机真的好用吗?有人工擦的干净吗...
- 谁是中国移动互联网的王者?360发布定制手机消息随感
- mysql查询性别语句_MySQL查询语句简单操作示例