minecraft-齿轮

602

### 题目描述

#### 样例





### 算法1

#### python 代码

class Solution(object):
def replaceSpaces(self, s):
"""
:type s: str
:rtype: str
"""
dat = s.split(' ')
data = ''
for i in dat:data += i + r'%20'
data = data[:-3]
return data


### 算法2

python大法好！

#### python 代码

from urllib.parse import quote
class Solution(object):
def replaceSpaces(self, s):
"""
:type s: str
:rtype: str
"""
return quote(s)


### 题目描述

blablabla

#### 样例

输入：9

——————

一共有31个1。


### 算法

#### Python3 代码

class Solution(object):
def NumberOf1(self,n):
"""
:type n: int
:rtype: int
"""
bin_num = str(bin(n))
if n >= 0:
new_bin_num = bin_num[2:]
j = 0
for i in new_bin_num:
if i == '1':
j += 1
return j
else:
new_bin_num = bin_num[3:]
index =32 - len(new_bin_num)
for i in new_bin_num:
if i == '1':
index += 1
return index


### 算法

#### Python 代码

class Solution(object):
def reOrderArray(self, array):
"""
:type array: List[int]
:rtype: void
"""
index = 0
temp0 = []
temp1 = []
while index < len(array):
if array[index] % 2 == 0:
temp1.append(array[index])
else:
temp0.append(array[index])
index += 1
index = 0
temp0.extend(temp1)
while index < len(temp0):
array[index] = temp0[index]
index += 1