LeetCode Reverse Bits 反置位值

题意:给定一个无符号32位整数,将其二进制形式左右反置,再以整型返回。
思路:循环32轮,将n往右挤出一位就补到ans的尾巴上。
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
if( !n ) return ;
uint32_t ans = ;
int i;
for(i=; i<; i++ )
{
ans <<= ;
if( n & )
ans |= ;
n >>=;
}
return ans;
}
};
Reverse Bits
LeetCode Reverse Bits 反置位值的更多相关文章
- 2016.5.16——leetcode:Reverse Bits(超详细讲解)
leetcode:Reverse Bits 本题目收获 移位(<< >>), 或(|),与(&)计算的妙用 题目: Reverse bits of a given 3 ...
- [LeetCode] Reverse Bits 翻转位
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- [leetcode] Reverse Bits
Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...
- leetcode reverse bits python
Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...
- [LeetCode] Reverse Bits 位操作
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- lc面试准备:Reverse Bits
1 题目 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...
- LeetCode 190. Reverse Bits (反转位)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- LeetCode Reverse Linked List II 反置链表2
题意:将指定的一段位置[m,n]的链表反置,返回链表头. 思路:主要麻烦在链表头,如果要从链表头就开始,比较特殊. 目前用DFS实现,先找到m-1的位置,再找到n+1的位置,中间这段就是否要反置的,交 ...
- LeetCode Reverse Nodes in k-Group 每k个节点为一组,反置链表
题意:给一个单链表,每k个节点就将这k个节点反置,若节点数不是k的倍数,则后面不够k个的这一小段链表不必反置. 思路:递归法.每次递归就将k个节点反置,将k个之后的链表头递归下去解决.利用原来的函数接 ...
随机推荐
- Apple Swift中文入门教程【转发】
1 简介 今天凌晨Apple刚刚发布了Swift编程语言,本文从其发布的书籍<The Swift Programming Language>中摘录和提取而成.希望对各位的iOS& ...
- 理解linux服务器mcelog如何工作
What are Machine Check Exceptions (or MCE)? A machine check exception is an error dedected by your s ...
- Asp.Net 之 Web.config 配置文件详解 -转
在asp.net中配置文件名一般默认是web.config.每个web.config文件都是基于XML的文本文件,并且可以保存到Web应用程序中的任何目录中.在发布Web应用程序时web.config ...
- 项目:IT资源共享资源(登录后端)<2>
公众号技术标签 小程序 PHP 源码 项目 ThinkPHP5.0目录结构,新建一个模块api,该模块下面有controller.model 目录,前者放控制器,写API接口(这里是简单的api写法) ...
- 对不起,给pandas配表情包太难了,pandas你该这么学,No.6
如果图片无法观看,请移步 https://blog.csdn.net/hihell 标题起的长,才能引起你的注意呢 昨天,有个家伙,留言给我说 嫌我不好好写博客 就知道给文章配表情包 在这里,郑重的回 ...
- HDFS(Hadoop Distributed File System )hadoop分布式文件系统。
HDFS(Hadoop Distributed File System )hadoop分布式文件系统.HDFS有如下特点:保存多个副本,且提供容错机制,副本丢失或宕机自动恢复.默认存3份.运行在廉价的 ...
- web版聊天框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Bitbucekt Reference
Bitbucket Server installation guide https://confluence.atlassian.com/bitbucketserver/bitbucket-serve ...
- HDU1425 A Chess Game
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1524 思路:题目就是给你一个拓扑图,然后指定点的位置放棋子,然后两人轮流移动棋子(题目中的边的关系),直到 ...
- Git练习1