算法笔记
穿拖鞋喜欢雷的饭
真的要做coder了?
展开
-
算法导论第八章伪码转C++ __桶排序
#include#includeusing namespace std;void ShowArray(double A[],int n){cout for (int i = 0; i cout cout }void BucketSort(double A[],int n) {//P112 , 默认输入范围[0,1) ,对于大数原创 2014-10-08 20:19:07 · 466 阅读 · 0 评论 -
Leetcode刷题6--数组继续
1.Single NumberGiven an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you imp原创 2015-01-05 08:50:36 · 492 阅读 · 0 评论 -
KMP算法初步理解
看了两天KMP算法,不知道理解的对不,初步理解总结如下:(主要是各种next数组把自己整晕了,有彻底懂的大神们再给指导下)首先是思路,“字符串匹配的KMP算法_知识库_博客园”http://kb.cnblogs.com/page/176818/,问题的关键落在求数组上,而求数组实际是对自身求匹配度,所以求next数组的子函数和主函数很类似,所以网上讨论的好像主要是两种next数组,最好把相原创 2015-01-20 10:17:11 · 625 阅读 · 0 评论 -
Leetcode记录7-单链表
1.Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the tw原创 2015-01-20 10:18:46 · 412 阅读 · 0 评论 -
leetcode刷题记录5--依旧数组
1.Gray Code Total Accepted: 21683 Total Submissions: 67384My SubmissionsThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negati原创 2014-12-12 11:10:26 · 468 阅读 · 0 评论 -
继续做leetcode上数组题3
1.Remove ElementGiven an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyon原创 2014-12-02 15:56:46 · 514 阅读 · 0 评论 -
做几个leetcode数组题二
1.Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecu原创 2014-11-19 19:25:27 · 682 阅读 · 0 评论 -
做几个leetcode数组题
1.Remove Duplicates from Sorted Array Total Accepted: 29864 Total Submissions: 91835My SubmissionsGiven a sorted array, remove the duplicates in place such that each element appear onlyonc原创 2014-11-18 13:00:57 · 549 阅读 · 0 评论 -
算法导论第六章伪码转C++ ___堆排序
heap.h:#includeusing namespace std;class Fheap{public: };int Parent(int i){return (i-1)/2;} //从0索引,i/2变成(i-1)/2 int LeftChild(int i){return 2*i + 1;} //从0索引, 2*i 变成2*i + 1 in原创 2014-10-08 20:10:41 · 454 阅读 · 0 评论 -
算法导论第八章伪码转C++_基数排序
#include#include //pow usedusing namespace std;void ShowArray(int A[],int n){ cout for (int i = 0; i cout cout }void CountingSort(int CpA[],int k,int n,int di) //k表示取值范围原创 2014-10-08 20:14:36 · 480 阅读 · 0 评论 -
算法导论第十章数据结构--双向链表
看的概念挺朦胧的,没有明确好双链表到底需要哪些方法,其实针对这种结构应该可以写很多方法,并没有什么特定标准。不过真是只看不练不行啊,一下手各种错误,各种溢出#includeusing namespace std;template struct Node{T value;Node* pre;Node* next;};template class原创 2014-10-10 13:07:28 · 919 阅读 · 0 评论 -
算法导论第八章伪码转C++_计数排序
#include#include"lei.h"#include // random usedusing namespace std;void ShowArray(int A[],int n){cout for (int i = 0; i cout cout }void CountingSort(int A[],int B[],int k,原创 2014-10-08 20:17:10 · 541 阅读 · 0 评论 -
算法导论第七章伪码转C++__快速排序
#includeusing namespace std;void ShowArray(int A[],int n){cout for (int i = 0; i cout cout }int Partition(int A[],int p,int r){int x = A[r - 1]; // r to r-1 ,这里r-1里,所以原创 2014-10-08 20:21:25 · 594 阅读 · 0 评论 -
算法导论第五章实例伪码转C++_最大子数组
1. 犯了一个错误,引发出对递归中变量定义的思考 P71递归中要看变量的使用范围,以及如果作为全局,下面语句是否会修改其值#include#includeusing namespace std;//find_maximum used//int mid; 这里犯了一个错误,看下面 ,递归中用变量,要考虑其是局部全局int mleft_sum,mleft_l原创 2014-09-15 18:43:49 · 504 阅读 · 0 评论 -
leetcode刷题记录4--依然数组
1.Valid Sudoku Total Accepted: 19171 Total Submissions: 69993My SubmissionsDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled原创 2014-12-12 11:09:18 · 506 阅读 · 0 评论