leetcode python3 简单题231. Power of Two
1.编辑器
我使用的是win10+vscode+leetcode+python3
环境配置参见我的博客:
链接
2.第二百三十一题
(1)题目
英文:
Given an integer, write a function to determine if it is a power of two.
Example 1:
Input: 1
Output: true
Explanation: 20 = 1
中文:
给定一个整数,编写一个函数来判断它是否是 2 的幂次方。
示例 1:
输入: 1
输出: true
解释: 20 = 1
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/power-of-two
(2)解法
使用二进制位运算,思路是:2的幂指数对应的二进制除了第一位是1其余都是0,而将这个数减一后,将得到互补的二进制,相与就得0
(耗时:48ms,内存:13.8M)
class Solution:def isPowerOfTwo(self, n: int) -> bool:return n > 0 and n & (n - 1) == 0
leetcode python3 简单题231. Power of Two相关推荐
- leetcode python3 简单题225. Implement Stack using Queues
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十五题 (1)题目 英文: Implement the following ...
- leetcode python3 简单题70. Climbing Stairs
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第七十题 (1)题目 英文: You are climbing a stair ca ...
- leetcode python3 简单题69. Sqrt(x)
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第六十九题 (1)题目 英文: Implement int sqrt(int x). ...
- leetcode python3 简单题53. Maximum Subarray
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十三题 (1)题目 英文: Given an integer array num ...
- leetcode python3 简单题58. Length of Last Word
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十八题 (1)题目 英文: Given a string s consists ...
- leetcode python3 简单题14. Longest Common Prefix
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第十四题 (1)题目 英文: Write a function to find th ...
- leetcode python3 简单题234. Palindrome Linked List
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百三十四题 (1)题目 英文: Given a singly linked li ...
- leetcode python3 简单题232. Implement Queue using Stacks
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百三十二题 (1)题目 英文: Implement the following ...
- leetcode python3 简单题226. Invert Binary Tree
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十六题 (1)题目 英文: Invert a binary tree. 中文 ...
最新文章
- alert在asp.net中如何使用??
- 你了解如何评估模型吗?
- 出现should be mapped with insert=“false“ update=“false“的解决方法
- 委托与事件代码详解与(Object sender,EventArgs e)详解
- 正数、负数、和小数正则表达式 ios_【3-17】使用正则表达式去掉字符串间的各种符号...
- java编程有一筐鸡蛋_一筐鸡蛋数学题标准答案公式-一筐鸡蛋标准答案图片详细解答版下载_东坡手机下载...
- BugkuCTF-Misc:Linux2
- oracle生成42位,Oracle HowTo:如何确定Oracle是32 Bit(位)的还是64 Bit(位)的?
- CRC32算法详细推导(2)
- TVM:使用 Auto-scheduling 来优化算子
- 再把鼻子涂黑的飞鸽沟通最简单
- 短消息代理(cmpp20 smproxy)要怎么创建java项目_基于华为smproxy开发的cmpp3
- 计算机变成英语,win10系统下计算器界面变成英文界面了怎么办
- 原创分享 计算机毕业设计PySpark+LSTM+Hadoop招聘推荐系统 招聘大数据 招聘数据分析 协同过滤算法(基于物品+基于用户) 招聘可视化大屏 就业推荐系统 就业数据分析
- 华为是ICT人才培养的“黑土地”,谁又是浇水人呢?
- EasyExcel · 写excel
- 金碟文件保存在服务器哪里,金蝶软件服务器地址在哪改
- Reinforced History Backtracking for Conversational Question Answering论文翻译
- windows与linux中,ping大数据包的命令格式
- ESP32S蓝牙03
热门文章
- centos安装软件后没有快捷键,创建桌面快捷键的方式【pycharm的快捷键】
- k3B软件下载_优麒麟20.10发布:简约、众智、兼容Windows有戏_办公软件
- php7 php5 区别,php7与php5的区别有哪些?
- c语言输入身高计算标准体重_女生标准身高体重对照表
- OSError: [Errno 22] Invalid argument: ‘\u202aC:\\Windows\\Fonts\\方正粗黑宋简体.ttf‘解决方案
- Freemarker简单封装
- hihocoder第218周:AC自动机
- 【转】Java 8十个lambda表达式案例
- 模版 ----- 实数二分
- 又是骗补贴的?清华虚拟学生华智冰翻车:AI换脸铸就人工智能