求助

剑指 Offer 15. 二进制中1的个数

编写一个函数,输入是一个无符号整数(以二进制串的形式),返回其二进制表达式中数字位数为 ‘1’ 的个数

我的第一版代码:

Help Wanted

Number of 1 Bits

Write a function that takes an unsigned integer (in binary string form) and returns the number of ‘1’ bits in its binary representation.

My first version of the code:

1
2
3
4
5
6
7
8
class Solution {
public:
int hammingWeight(uint32_t n) {
if(n == 1) return 1;
if(n == 0) return 0;
return n&1 + hammingWeight(n>>1);
}
};

这个我看起来问题不大啊,边界条件设置好,n&1 计算最低位是不是 1 ,再加上递归调用 n 的右移1 位。

This looks fine to me. The base cases are set up, n&1 checks whether the lowest bit is 1, plus the recursive call on n shifted right by 1 bit.

WikiC/C++LeetCode

前言

在闲暇时间浏览 GitHub 时,在推荐页面发现了这样一个项目,项目的简介里写着:

An index & manager of Onedrive based on serverless. Can be deployed to Heroku/Glitch/Vercel/SCF/FG/FC/CFC/PHP web hosting/VPS.

凭借我长期的白嫖经验,以及大学英语 5.8 级的水平,迅速捕捉到几个熟悉的关键词:manager of Onedrive,Heroku,Vercel。关于 Heroku 我曾经写过一篇 Heroku 搭建 V2ray 教程 在 Bing 的搜索权重相当之高,高到我自己都属实没想到啊!

Preface

While browsing GitHub in my spare time, I came across this project on the recommendations page. Its description read:

An index & manager of Onedrive based on serverless. Can be deployed to Heroku/Glitch/Vercel/SCF/FG/FC/CFC/PHP web hosting/VPS.

Relying on my long experience with freeloading and my college English level of 5.8, I quickly caught a few familiar keywords: manager of Onedrive, Heroku, Vercel. I once wrote a post about Heroku — Heroku 搭建 V2ray 教程 (Heroku V2ray Tutorial) — which ranks remarkably high on Bing, so high that even I didn’t expect it!

分享VPS

阅读更多
Music

机房预约系统需求

系统简介

学校现有几个规格不同的机房,由于使用时经常出现"撞车"现象,现开发一套机房预约系统,解决这一问题。

1548682783885

Computer Room Reservation System Requirements

System Introduction

The school has several computer rooms of different specifications. Since “collision” often occurs when using them, a computer room reservation system is now developed to solve this problem.

1548682783885

WikiC/C++C++案例