separate odd and even numbers in an array in O(n) time complexity and O(1) space complexity
来源:互联网 发布:严防网络泄密十条禁令 编辑:程序博客网 时间:2024/05/29 18:05
Problem: as title
Solution: same as partition algorithm in quick sort.
/**after processing, odd number is in the left part, even number in the right part*/void separate(int a[], int size) { if (size <= 0) { return; } for(int i = 0, j = size -1, t = 0;i < j;) { for(; (i < j) && ((a[i] & 0x1) == 1); i++); //empty loop for(; (i < j) && ((a[j] & 0x1) == 0); j--); //empty loop if (i < j) { t = a[i]; a[i] = a[j]; a[j] = t; i++; j--; } }}
- separate odd and even numbers in an array in O(n) time complexity and O(1) space complexity
- Time Complexity and Space Complexity
- Sort a linked list in O(n log n) time using constant space complexity
- leetcode_Sort a linked list in O(n log n) time using constant space complexity.
- Sort a linked list in O(n log n) time using constant space complexity.
- Sort a linked list in O(n log n) time using constant space complexity.
- Sort a linked list in O(n log n) time using constant space complexity.
- Sort a linked list in O(n log n) time using constant space complexity.
- Sort a linked list in O(n log n) time using constant space complexity.
- leetcode Sort a linked list in O(n log n) time using constant space complexity.
- leetcode Sort List (Sort a linked list in O(n log n) time using constant space complexity)
- 算法的基础知识( Time Complexity & Space Complexity& Big O notation)
- Solution to Maximum Subarray in linear-time algorithm with time complexity is O(n)
- Find duplicates in O(n) time and O(1) extra space
- Given an array [a1b2c3d4] convert to [abcd1234] with 0(1) space and O(n) time
- Time and Space Complexity of Recursive Algorithms
- Problem complexity and method efficiency in optimization
- Complexity.and.Cryptography.An.Introduction
- 轻松搞定面试中的链表题目
- Excel计算XX天以后的日期
- c# 扩展方法的理解
- eclipse设置java虚拟机内存
- ÓÉÓÚl½ӷ½ÔÚһ¶Îʱ¼äºóûÓÐÕýȷ´ð¸´»òl½ӵÄÖ÷»úûÓз´Ӧ£¬l½ӳ¢ÊÔʧ°ܡ£ svn: Can't connect to host '172.18.77.
- separate odd and even numbers in an array in O(n) time complexity and O(1) space complexity
- erlang的dict模块函数方法介绍
- FFMpeg SDK 开发手册 [转]
- spirng声明式事务配置
- Android内核和驱动篇-Android内核介绍
- 64bit windows 8 安装 32bit PowerDesinger并且连接mysql
- WORD目录问题
- Python中的range()函数
- 垃圾回收机制