464
来源:互联网 发布:人工智能医疗实验室 编辑:程序博客网 时间:2024/06/06 04:50
5.5
使用的快排,一直超时,整个人都不好了。
今天终于找到了错误。
while (l < h && A[h] > key){ --h; } A[l] = A[h]; while(l < h && A[l] <= key){ ++l; }
原来是这里,少了一个等于号。只判断了大于和小于的情况,没有判断等于,这样就造成了死循环。
所以就一直一直超时,真的是要很细心,很认真才可以呢。
归并排序和堆排序一直一直懒得去好好学习,等着有时间也看看吧。
复杂度O(nlogN)的算法,还是要多看看的。
天天用插入排序和冒泡排序,也不行吖。
public class Solution { /** * @param A an integer array * @return void */ public void sortIntegers2(int[] A) { int heigh = A.length-1; int low = 0; sort(A,low,heigh);// Write your code here } public int[] sort(int[] A ,int low,int height){ if (low >= height){ return A; } int h = height; int l = low; int key = A[low]; while (l < h){ while (l < h && A[h] > key){ --h; } A[l] = A[h]; while(l < h && A[l] <= key){ ++l; } A[h] = A[l]; } A[l] = key; sort(A,low,l-1); sort(A,l+1,height); return A; }}
0 0
- 464
- ocp-464
- NYOJ 464 Cookies
- NYOJ 464题 Cookies
- NYOJ 464 Cookies
- cf 464 Restore Cube
- Android 464XLAT
- 464 Cookies【水题】
- Android 464XLAT
- #464 Sort Integers II
- 464_HttpURLConnection的post
- Codeforces 464B. Restore Cube
- 【codeforces】 464B Restore Cube
- NYOJ 464 Cookies【简单题】
- codeforces 464c 465e
- Codeforces 464B Restore Cube
- [leetcode 464]Can I Win
- Leetcode 464 can i win
- fiddler 测试Android App的网速
- 浅析Java中CountDownLatch用法
- CentOS 安装MySQL5.7
- 最新JREBEL使用方式
- 从程序员到项目经理(15):项目管理三大目标
- 464
- 一个for循环实现九九乘法表
- python爬取数据并将其存入mongodb
- CentOS7安装iptables防火墙
- 探究Activity
- Backtrader量化平台教程(七)Optimizer
- My Recommender Notes
- Spring IOC和AOP 原理彻底搞懂
- EXCEL:SUMIFS多条件求和2(筛选效果),含字符串转数组用法