lintcode/leetcode由易至难第3题:选择排序
2017-05-08 14:18
453 查看
public class Solution { /** * @param A an integer array * @return void */ //重点是记录指针!!!!派一个指针不断向后找 public void sortIntegers(int[] A) { // Write your code here if (A == null || A.length == 0 || A.length == 1) return; for(int i = 0; i < A.length - 1; i++){ //此处判断条件不能为i < A.length,否则第11行溢出 int target = i + 1; for(int j = target + 1; j < A.length; j++){ if(A[target] >= A[j]){ target = j; } } if(A[i] >= A[target]){ int tmp = A[i]; A[i] = A[target]; A[target] = tmp; } } } }
相关文章推荐
- LintCode 链表插入排序
- LintCode Remove Duplicates from Sorted Array II 删除排序数组中的重复数字 II
- LintCode-剑指Offer-(112)删除排序链表中的重复元素
- LintCode_63_搜索旋转排序数组 II
- LintCode_112_删除排序链表中重复的元素
- 排颜色问题——数组 leetcode lintcode
- lintcode convert-sorted-array-to-binary-search-tree-with-minimal-height 把排序数组转换为高度最小的二叉搜索树
- LintCode-剑指Offer-(165)合并两个排序链表
- LintCode-剑指Offer-(28)寻找旋转排序数组中的最小值
- LintCode-删除排序链表中的重复元素
- lintcode ----删除排序数组中的重复数字
- LintCode Merge Sorted ArrayII 合并排序数组 II
- lintcode 容易题:Remove Duplicates from Sorted Array 删除排序数组中的重复数字
- LintCode SortedArrayToBST 把排序数组转换为高度最小的二叉搜索树
- lintcode-排序列表转换为二分查找树-106
- LintCode-排序矩阵中的从小到大第k个数
- LintCode 删除排序数组中的重复数字
- lintcode: 把排序数组转换为高度最小的二叉搜索树
- lintcode 中等题:search in rotated sorted arrayII 搜索旋转排序数组II
- lintcode:整数排序