摘要: Maximum Subarray Question Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given 阅读全文
posted @ 2017-03-12 21:50 清水汪汪 阅读(190) 评论(0) 推荐(1) 编辑
摘要: Merge Sort(归并排序) 思想 利用分治的思想,具体实现也就是递归,不断的将问题话分为更小的子问题,当子问题中规模为1的时候,认为数组已经有序了,然后再将子问题求得的结果不断的合并。也就是将长度为1的两个数组合并到长度为2的数字,依次合并下去。 合并的过程就是依次比较两个数组,将较小的数复制 阅读全文
posted @ 2017-03-12 16:15 清水汪汪 阅读(854) 评论(0) 推荐(1) 编辑
摘要: 插入排序(Insertion Sort) 算法描述 依次比较元素,将元素依次往后移动,挪出一个合适的位置,然后将值放入其中。 具体实现 C++ include include using namespace std; class Solution { public: //插入排序算法 void in 阅读全文
posted @ 2017-03-12 15:05 清水汪汪 阅读(155) 评论(0) 推荐(1) 编辑
摘要: 2 Color Dutch National Flag Problem 问题 a[0..n 1]中包含红元素或蓝元素;重新放置使得 红元素均在蓝元素之前。 循环不变式 每一次循环,a[0...k 1]是红色 实例代码 C++ include include using namespace std; 阅读全文
posted @ 2017-03-12 14:41 清水汪汪 阅读(301) 评论(0) 推荐(1) 编辑
摘要: LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse the first k characters for every 2k characters co 阅读全文
posted @ 2017-03-12 11:54 清水汪汪 阅读(217) 评论(0) 推荐(1) 编辑