*[Lintcode]Interleaving Positive and Negative Numbers 交错正负数
来源:互联网 发布:怎么样给数据库加锁 编辑:程序博客网 时间:2024/06/04 23:32
Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.
Example
Given [-1, -2, -3, 4, 5, 6]
, after re-range, it will be [-1, 5, -2, 4, -3, 6]
or any other reasonable answer.
例:-1 -2 -3 4 5 start = 1 end = 4 -1 -2 3 4 5 start = 0, end = 3 -1 -2 3 4 start = 0, end = 3 确保占多数的一组先移动一位。
class Solution { /** * @param A: An integer array. * @return: void */ public void rerange(int[] A) { if(A.length <= 1) return; Arrays.sort(A); int start = 0, end = A.length - 1; if(A.length % 2 != 0 && A[A.length / 2] > 0) end = A.length - 2; if(A.length % 2 != 0 && A[A.length / 2] < 0) start = 1; while(start < end) { int tmp = A[start]; A[start] = A[end]; A[end] = tmp; start += 2; end -= 2; } }}
0 0
- *[Lintcode]Interleaving Positive and Negative Numbers 交错正负数
- 144.Interleaving Positive and Negative Numbers-交错正负数(中等题)
- Lintcode - Interleaving Positive and Negative Numbers
- lintcode:Interleaving Positive and Negative Numbers
- LintCode Interleaving Positive and Negative Numbers
- 代码面试题:Interleaving Negative and Positive Numbers 正负交替
- Interleaving Positive and Negative Numbers
- Interleaving Positive and Negative Numbers
- [leetcode]Interleaving Positive and Negative Numbers
- LintCode-交错正负数
- LintCode 交错正负数
- lintcode --交错正负数
- LintCode:交错正负数
- Lintcode144 Interleaving Positive And Negative Numbers solution 题解
- lintcode-交错正负数-144
- lintcode 144交错正负数
- lintcode(144)交错正负数
- 交错正负数
- 图像几何变换
- spark 教程
- Good Luck in CET-4 Everybody! HDU 1847
- eclipse对项目进行分类管理
- REST 表现层状态转换 架构说明
- *[Lintcode]Interleaving Positive and Negative Numbers 交错正负数
- python virtualenv虚拟化环境
- SQL server 2008R2 数据库备份和还原
- Oracle 11g 新特性 -- RAC One Node 说明一.RAC ONE NODE 理论说明
- vim使用教程(全)-最好的编辑器
- programming in lua 第二章笔记
- 自定义布局实现侧滑菜单2
- c语言指针的指针使用
- self.navigationcontroller是nil吗?