当前位置:网站首页>LeetCode 剑指offer 21.调整数组顺序使奇数位于偶数前面(简单)
LeetCode 剑指offer 21.调整数组顺序使奇数位于偶数前面(简单)
2022-08-10 05:32:00 【生信研究猿】
python(左右两边各一个指针往中间遍历)
class Solution:
def exchange(self, nums: List[int]) -> List[int]:
if(len(nums)==0):
return nums
left = 0
right = len(nums) -1
temp = nums[0]
while(left!=right):
while(left<right and nums[right]%2==0):
right -=1
nums[left] = nums[right]
while(left<right and nums[left]%2!=0):
left +=1
nums[right] = nums[left]
nums[left] = temp
return nums
边栏推荐
- Small program wx.request simple Promise package
- 先人一步,不再错过,链读APP即将上线!
- String常用方法
- cesium add point, move point
- 【List练习】遍历集合并且按照价格从低到高排序,
- 泛型笔记()()()
- MySql constraints
- cesium listens to map zoom or zoom to control whether the content added on the map is displayed
- Module build failed TypeError this.getOptions is not a function报错解决方案
- Linux database Oracle client installation, used for shell scripts to connect to the database with sqlplus
猜你喜欢
随机推荐
Batch add watermark to pictures batch scale pictures to specified size
ORACLE system table space SYSTEM is full and cannot expand table space problem solving process
Using sqlplus to operate database in shell script
Smart contracts and DAPP decentralized applications
行盒子的盒模型
Common class BigDecimal
cesium listens to map zoom or zoom to control whether the content added on the map is displayed
每天一个小知识点
Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
Chain Reading Recommendation: From Tiles to Generative NFTs
The latest and most complete digital collection sales calendar-07.27
共识计算和激励机制
链读好文:Jeff Garzik 推出 Web3 制作公司
Bifrost 同步数据库实现微服务跨库数据同步
Timer (setInterval) on and off
先人一步,不再错过,链读APP即将上线!
win12 modify dns script
impdp import data
IDEA的database使用教程(使用mysql数据库)
关于cfar检测的学习及仿真








