Lintcode 463 整数排序
来源:互联网 发布:万达乐园和迪士尼 知乎 编辑:程序博客网 时间:2024/06/04 18:42
463 整数排序
给一组整数,按照升序排序,使用选择排序,冒泡排序,插入排序或者任何 O(n2) 的排序算法。
C++代码 冒泡法
public class Solution { /** * @param A an integer array * @return void */ public void sortIntegers(int[] A) { // Write your code here if(A==null || A.length<=1) return; int n = A.length; for(int i=n-1;i>=0;i--){ for(int j=0;j<i;j++){ if(A[j]>A[j+1]){ swap(A,j,j+1); } } } } public void swap(int[] A,int i,int j){ int tmp = A[i]; A[i] = A[j]; A[j] = tmp; }}
python代码
class Solution: # @param {int[]} A an integer array # @return nothing def sortIntegers(self, A): # Write your code here i = 0 j = len(A) - 1 self.quick_sort(A, i, j) def quick_sort(self, A, low, high): if low < high: i = low j = high tmp = A[low] while i < j: while i < j and A[j] >= tmp: j -= 1 A[i] = A[j] while i < j and A[i] < tmp: i += 1 A[j] = A[i] A[i] = tmp self.quick_sort(A, low, i-1) self.quick_sort(A, i+1, high)
阅读全文
0 0
- Lintcode 463 整数排序
- lintcode 463整数排序 lintcode 464整数排序II
- lintcode python代码 463 整数排序
- (lintcode)第463题整数排序
- LintCode 第463题 整数排序
- LintCode:整数排序
- 【LintCode】整数排序II
- LintCode【入门】整数排序
- 整数排序II-lintcode
- lintcode-入门-整数排序
- LintCode-整数排序
- LintCode-整数排序 II
- 整数排序-LintCode
- LintCode 整数排序
- LintCode 整数排序 II
- LintCode 整数排序
- Lintcode整数排序
- 整数排序-LintCode
- 远程连接服务器数据库报错:Host ‘XXXXXX’ is blocked because of many connection errors
- 【备忘】动力节点MySQL数据库视频 86集下载
- ReentrantLock源码解析
- Python 容器API
- Java中常用进制转换
- Lintcode 463 整数排序
- WPF架构分析
- Linux 内核文件系统关键数据结构
- KMP子字符串查找算法.java
- div中的内容垂直居中的五种方法
- Git版本控制使用方法入门教程
- 深度学习Java类库deeplearning4j 学习笔记-MNIST手写数字分类问题
- Hrbust 2315 Time ("科林明伦杯"哈理工第六届团队赛)
- Tolua使用笔记一:开始使用Tolua的准备工作与lua文件读取方法