当前位置:网站首页>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
边栏推荐
猜你喜欢

The complex "metaverse" will be interpreted for you, and the Link Reading APP will be launched soon!

String common methods

String常用方法

链表API设计

树结构——2-3树图解

One step ahead, don't miss it again, the chain reading APP will be launched soon!

Count down the six weapons of the domestic interface collaboration platform!

事务、存储引擎

Collection tool class

栈和队列
随机推荐
Models corresponding to each architecture instruction set
AWR1843型号毫米波雷达使用
最新最全的数字藏品发售日历-07.26
el-dropdown drop-down menu style modification, remove the small triangle
error in ./node_modules/cesium/Source/ThirdParty/zip.js
网络安全3
Chain Reading|The latest and most complete digital collection sales calendar-08.02
去中心化和p2p网络以及中心化为核心的传统通信
Batch add watermark to pictures batch scale pictures to specified size
图片批量添加水印批量加背景缩放批量合并工具picUnionV4.0
Decentralized and p2p networks and traditional communications with centralization at the core
PCL,VS配置过程中出现:用 _sopen_s 代替 _open, 或用_CRT_SECURE_NO_WARNNINGS错误
【笔记】集合框架体系 Collection
Chain Reading Recommendation: From Tiles to Generative NFTs
链读好文:Jeff Garzik 推出 Web3 制作公司
One step ahead, don't miss it again, the chain reading APP will be launched soon!
redis---非关系型数据库(NoSql)
第六次实验
The submenu of the el-cascader cascade selector is double-clicked to display the selected content
shell脚本中利用sqlplus操作数据库