当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Set Sources Resources and other folders in the IDEA project
redis集群模式
21天挑战杯MySQL——Day06
毫米波雷达数据集Scorp使用
Batch add watermark to pictures batch add background zoom batch merge tool picUnionV4.0
链读 | 最新最全的数字藏品发售日历-07.28
ORACLE system table space SYSTEM is full and cannot expand table space problem solving process
PCL,VS配置过程中出现:用 _sopen_s 代替 _open, 或用_CRT_SECURE_NO_WARNNINGS错误
Database Notes Create Database, Table Backup
OSPF实验
【笔记】集合框架体系 Collection
win12 修改dns脚本
行盒子的盒模型
Link reading good article: What is the difference between hot encrypted storage and cold encrypted storage?
数据库 笔记 创建数据库、表 备份
棋类游戏-五子棋小游戏
Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
堆的原理与实现以及排序
视图【】【】【】【】
matlab中的常用的类型转换