知识点

1. 整数的二进制表示法

2. 十进制和二进制的转换

http://baike.baidu.com/view/1426817.htm

3. 负整数的表示(原码,补码,反码)

http://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html

4. 位操作 Bit Operation

左移 Left Shift      <<

右移 Right Shift    >>

与 And   &

或  Or   |

非  Neg   ^

    public int countOnes(int num) {
int numOfOne = 0;
int mask = 0;
for(int i = 0; i < 32; i++){
mask = (1 << i);
if((mask & num) != 0){
numOfOne++;
} }
return numOfOne;
}

LintCode Count 1 in Binary的更多相关文章

  1. 365. Count 1 in Binary【LintCode java】

    Description Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return  ...

  2. lintcode :Count 1 in Binary 二进制中有多少个1

    题目: 二进制中有多少个1 49% 通过 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111 ...

  3. Lintcode: Count of Smaller Number

    Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 1 ...

  4. [LintCode] Serialize and Deserialize Binary Tree(二叉树的序列化和反序列化)

    描述 设计一个算法,并编写代码来序列化和反序列化二叉树.将树写入一个文件被称为“序列化”,读取文件后重建同样的二叉树被称为“反序列化”. 如何反序列化或序列化二叉树是没有限制的,你只需要确保可以将二叉 ...

  5. Count 1 in Binary

    Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return 1 Given 5, r ...

  6. [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  7. [LintCode] Count and Say 计数和读法

    The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...

  8. LintCode Maximum Depth of Binary Tree

    1 /** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, ...

  9. Lintcode: Remove Node in Binary Search Tree

    iven a root of Binary Search Tree with unique value for each node. Remove the node with given value. ...

随机推荐

  1. vs2012编译Qwt

    主题:vs2012编译Qwt ------------------------------------------------------------------------- 参照网络地址: htt ...

  2. Windows Internals学习笔记(七)Image Loader

    参考资料: 1. <Windows Internals> 2. Fibers 知识点: ● 当一个进程在系统上启动时,内核将创建一个进程对象来代表它,并执行各种内核相关的初始化任务.然而, ...

  3. 《BI那点儿事》数据流转换——排序

    排序转换允许对数据流中的数据按照某一列进行排序.这是五个常用的转换之一.连接数据源打开编辑界面,编辑这种任务.不想设置为排序列的字段不要选中,默认情况下所有列都会选中.如图所示,按照TotalSuga ...

  4. 《BI那点儿事》SSRS图表和仪表——雷达图分析三国超一流谋士、统帅数据(图文并茂)

    雷达图分析三国超一流谋士.统帅数据,献给广大的三国爱好者们,希望喜欢三国的朋友一起讨论,加深对传奇三国时代的了解 建立数据环境: -- 抽取三国超一流谋士TOP 10数据 DECLARE @t1 TA ...

  5. jQuery核心之jQuery Object及其相关的常用方法

    1.jQuery Object 和 原生的DOM对象之间有许多方法是不一样的,用jQuery的方法大部分情况下返回的是jQuery Object,但是jQuery也提供了一些方法可以很轻松的获取原生的 ...

  6. iOS 推送通知处理

    //这是程序杀死后再通过点击通知进入时调用的方法 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOpti ...

  7. (九)errno和perror、标准IO

    3.1.6.文件读写的一些细节3.1.6.1.errno和perror(1)errno就是error number,意思就是错误号码.linux系统中对各种常见错误做了个编号,当函数执行错误时,函数会 ...

  8. Deep Learning 12_深度学习UFLDL教程:Sparse Coding_exercise(斯坦福大学深度学习教程)

    前言 理论知识:UFLDL教程.Deep learning:二十六(Sparse coding简单理解).Deep learning:二十七(Sparse coding中关于矩阵的范数求导).Deep ...

  9. [Java基础]循环结构3

    [Java基础]循环结构3 break 与 continue 中断循环... /** 文件路径:G:\JavaByHands\循环语句\ 文件名称:BreakTest.java 编写时间:2016/6 ...

  10. Less基础知识~~~实现css

    首先献上我学习网址 http://www.bootcss.com/lesscss.html 就是通过less.js的调用,更好的实现css样式布局,更简易化. 最近看前端的职位要求需简单理解less之 ...