leetcode-13双周赛-1256-加密数字
题目描述:编码

方法一:
class Solution(object):
def encode(self, n):
if n == 0: return ""
n -= 1
A = ['' if n % 2 == 0 else '']
# 01 2345
e = 2
while n >= e:
n -= e
e *= 2
A.append('' if n % e < (e/2) else '')
return "".join(A[::-1])
leetcode-13双周赛-1256-加密数字的更多相关文章
- C#版 - Leetcode 13. 罗马数字转整数 - 题解
C#版 - Leetcode 13. 罗马数字转整数 - 题解 Leetcode 13. Roman to Integer 在线提交: https://leetcode.com/problems/ro ...
- LeetCode:移除K位数字【402】
LeetCode:移除K位数字[402] 题目描述 给定一个以字符串表示的非负整数 num,移除这个数中的 k 位数字,使得剩下的数字最小. 注意: num 的长度小于 10002 且 ≥ k. nu ...
- Leetcode之二分法专题-374. 猜数字大小(374. Guess Number Higher or Lower)
Leetcode之二分法专题-374. 猜数字大小(374. Guess Number Higher or Lower) 我们正在玩一个猜数字游戏. 游戏规则如下:我从 1 到 n 选择一个数字. 你 ...
- js运算【按位非】~ (index = ~~this.userIndex)(~~ 双破折号 如果是数字返回数字,如果不是数字 返回0)
index = ~~this.userIndex ~~ 双破折号 如果是数字返回数字,如果不是数字 返回0 这个运算符有点意思:按位非[~] 先来几个例子: ~undefined: -1 ~false ...
- TrueCrypt与CryptSetup双系统全盘加密(图文)
http://blog.topsec.com.cn/truecrypt%E4%B8%8Ecryptsetup%E5%8F%8C%E7%B3%BB%E7%BB%9F%E5%85%A8%E7%9B%98% ...
- LeetCode 第 15 场双周赛
1287.有序数组中出现次数超过25%的元素 1288.删除被覆盖区间 1286.字母组合迭代器 1289.下降路径最小和 II 下降和不能只保留原数组中最小的两个,hacked. 1287.有序数组 ...
- Java实现 LeetCode第30场双周赛 (题号5177,5445,5446,5447)
这套题不算难,但是因为是昨天晚上太晚了,好久没有大晚上写过代码了,有点不适应,今天上午一看还是挺简单的 5177. 转变日期格式 给你一个字符串 date ,它的格式为 Day Month Yea ...
- LeetCode第8场双周赛(Java)
这次我只做对一题. 原因是题目返回值类型有误,写的是 String[] ,实际上应该返回 List<String> . 好吧,只能自认倒霉.就当涨涨经验. 5068. 前后拼接 解题思路 ...
- LeetCode 第 14 场双周赛
基础的 api 还是不够熟悉啊 5112. 十六进制魔术数字 class Solution { public: char *lltoa(long long num, char *str, int ra ...
随机推荐
- 理解Java主函数中的"String[] args"
public class Understand_String_args { public static void main(String[] args) { System.out.printf(&qu ...
- 【leetcode】983. Minimum Cost For Tickets
题目如下: In a country popular for train travel, you have planned some train travelling one year in adva ...
- 【leetcode】985. Sum of Even Numbers After Queries
题目如下: We have an array A of integers, and an array queries of queries. For the i-th query val = quer ...
- python--函数的返回值、函数参数的使用、名称空间与作用域、函数嵌套、函数对象
今天学习内容有函数的返回值.函数参数的使用.名称空间与作用域.函数嵌套. 下来我们一一查看. 函数的返回值 看几个栗子: def func(x): y=func() print(y) def foo( ...
- QTcpSocket学习
一.涉及到的函数 监听:tcpServer->listen(QHostAddress::LocalHost, 6666) 错误信息:tcpServer->errorString() 新连接 ...
- SCP-bzoj-1019
项目编号:bzoj-1019 项目等级:Safe 项目描述: 戳这里 特殊收容措施: 对于一个hanoi,知道了各种移动操作的优先级,也就确定了方案.可以证明对于盘子数为N的hanoi,任意移动方案都 ...
- Linux运维学习网站收藏
Linux运维之道 1> http://www.linuxidc.com/ //Linux公社,收藏Linux学习的很多知识 2> http://http://www.jb51 ...
- Alpha冲刺阶段博客目录
Alpha冲刺阶段博客目录 Scrum Meeting 时间 链接 内容 第六周 https://www.cnblogs.com/error0/p/11815255.html 需求分析 第七周 htt ...
- 洛谷 P2522 [HAOI2011]Problem b (莫比乌斯反演+简单容斥)
题目描述 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 输入输出格式 输入格式: 第一行一个整数 ...
- javascript 对象的设计模式
1.为什么学习设计模式:http://www.iteye.com/news/32092 或 https://blog.csdn.net/pigpigpig4587/article/details ...