题目:
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]相关推荐

  1. 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的幂 ...

  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. 翻译: 写一个函数 ...

  3. Leet Code OJ 118. Pascal's Triangle [Difficulty: Easy]

    题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

最新文章

  1. 省钱方便网上手机充话费
  2. oracle case grouping,ORACLE GROUPING函數的使用
  3. python是用c写的吗-python和c语言的区别是什么
  4. Oracle数据库12cR2(项目实战之二):Linux系统安装Oracle12.2
  5. Nginx部署静态页面及引用图片有效访问的两种方式
  6. 剑指Offer值字符串的排列
  7. OSChina 周三乱弹 —— 程序员,老了会是怎么样?
  8. poj 1969 Count on Canton 摘规律
  9. android listview固定内容,Android ListView 列表分隔,条目中添加分类信息(文字,图片等)...
  10. 636. 函数的独占时间
  11. K8S学习笔记之借助Minikube完成在windows环境下Kubernetes的单节点搭建-(超级简单)
  12. 【有手就行】电脑蓝屏恶搞(附带一键复原方法)
  13. 【python】CNN算法
  14. H5分享带缩略图,描述,微信内分享到好友,朋友圈等
  15. QLabel显示QImage时报错
  16. 丧心病狂!最新NLP模型的写作水平已突破次元壁
  17. Chrome/Edge插件-在线视频画质增强,支持视频加速
  18. 可擦玻璃平顶的机器人_擦玻璃机器人的优点和缺点各是什么?智能擦窗机真的好用吗?有人工擦的干净吗...
  19. 谁是中国移动互联网的王者?360发布定制手机消息随感
  20. mysql查询性别语句_MySQL查询语句简单操作示例

热门文章

  1. 石子合并(GarsiaWachs算法)
  2. 使用VS2013编译Lua5.3.2
  3. 7.OD-字符串参考
  4. Socket重叠IO
  5. 如何使用Appverifier ?
  6. C++的查看指针指向空间的所在的区域(是堆还是栈或者静态)和大小
  7. 线程、进程、多线程、多进程和多任务有啥关系?
  8. 分析 Go time.After 引起内存暴增 OOM 问题
  9. 短视频内容理解与生成技术在美团的创新实践
  10. CEV模型与质量甜点算法设计