由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - bit manipulation 小题
相关主题
抛砖引玉,glassdoor上看来的zenefits题目a question about bits operation
问个careercup上的老题目,看不懂答案One question on Careercup
请教一道题目Ask a amazon question from careercup.
看programming pearl进行时的感想看到一个题目
Given two sorted list, find the k smallest number (binary search)这题怎么做?
就差一点了,接着求祝福问道面试题
看一道面试题Google电话面试题目
Google 面试题 一道问一道题
相关话题的讨论汇总
话题: next话题: smallest话题: largest话题: 小题
进入JobHunting版参与讨论
1 (共1页)
h******3
发帖数: 351
1
一个老题
Given an integer, print the next smallest and next largest number that have
the same number of 1 bits in their binary representation.
关于next smallest, next largest, 我的理解是比如
a = 347 = 101011011
next smallest = 111111 = 63
next largest = 111111000 = 504
career cup书的solution 运行了一下
next smallest = 343 = 101010111
next largest = 349 = 101011101
给我解释一下吧, 如果以前讨论过, 给个连接, 多谢.
r****o
发帖数: 1950
2
careercup上的对阿。
从后往前找到第一个0,然后跟左右两边临近的1交换就可以了吧。

have

【在 h******3 的大作中提到】
: 一个老题
: Given an integer, print the next smallest and next largest number that have
: the same number of 1 bits in their binary representation.
: 关于next smallest, next largest, 我的理解是比如
: a = 347 = 101011011
: next smallest = 111111 = 63
: next largest = 111111000 = 504
: career cup书的solution 运行了一下
: next smallest = 343 = 101010111
: next largest = 349 = 101011101

h******3
发帖数: 351
3
谢谢, ^_^.
next smallest = the smallest among larger ones
next largest = the largest among smaller ones.
书上貌似对的. 找大的, 从右到左扫描, 碰到1后面的零, 变成1, 然后把它右边的一个
1变成0,然后把右边的1尽量往右移动.

【在 r****o 的大作中提到】
: careercup上的对阿。
: 从后往前找到第一个0,然后跟左右两边临近的1交换就可以了吧。
:
: have

1 (共1页)
进入JobHunting版参与讨论
相关主题
问一道题Given two sorted list, find the k smallest number (binary search)
Search in a sorted, rotated list就差一点了,接着求祝福
贡献一道面试题看一道面试题
Given an array of N integers from range [0, N] and one is missing. Find the missing number.Google 面试题 一道
抛砖引玉,glassdoor上看来的zenefits题目a question about bits operation
问个careercup上的老题目,看不懂答案One question on Careercup
请教一道题目Ask a amazon question from careercup.
看programming pearl进行时的感想看到一个题目
相关话题的讨论汇总
话题: next话题: smallest话题: largest话题: 小题