谷歌面试题(4)
来源:互联网 发布:jsp与javascript的区别 编辑:程序博客网 时间:2024/05/17 02:10
原题:
// Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3]....// For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4].
答案:
public class Solution { public void wiggleSort(int[] nums) { for(int i = 1; i < nums.length; i++) { int current = nums[i - 1]; if((i % 2 == 1) == (current > nums[i])) { nums[i - 1] = nums[i]; nums[i] = current; } } }}
阅读全文
0 0
- 谷歌面试题(4)
- 谷歌面试题(2)
- 谷歌面试题(3)
- 谷歌面试题(5)
- 谷歌面试题(6)
- 谷歌面试题(7)
- 谷歌面试题(8)
- 谷歌面试题(9)
- 面试题(4)
- 面试题(4)
- 面试题(4)
- ACM初赛试题(4)
- Java面试题(4)
- 华为机试题(4)
- 华为机试题(4)
- ios面试题(4)
- java面试题(4)
- Android面试题(4)
- jQuery知识总结
- Java大数类排序
- 20个非常有用的Java程序片段
- knockout的默认选中设置
- R_地图上的迷你直方图
- 谷歌面试题(4)
- Keil 5无法设断点
- ubuntu临时关闭ipv6
- pch文件的创建
- javascript 判断对象是否为空的方法总结
- 日期工具类
- Maven入门(含实例教程)
- 2017大数据版图
- windows 获取当前用户的sid