携程笔试题
给定一个整形数组, 将数组中所有的0移动到末尾, 非0项保持不变;
问题描述
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
实例
For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].
注意事项
Note:
1、You must do this in-place without making a copy of the array.
2、Minimize the total number of operations.
#!/usr/bin/env python
# coding:utf-8
""""
Name: 01_携程_移动数组中的0.py
Date: 2018/2018/30
Connect: [email protected]
Author: lvah
Desc:
"""
# array = [0, 7, 0, 2, 1, 1, 3, 4, 1, 0, 0]
#
# print sorted(array, key=lambda x: 1 if x == 0 else 0)
#
# li = ['hello', 'world', ';aa', 'c']
# print sorted(li, key=lambda x: len(x))
# print sorted(li, key=len)
li = ['12', '1', '4', '89']
print sorted(li, key=int)