随笔分类 -  算法

摘要:本文按照此结构展开:1. 问题描述 2. 朴素模式匹配算法 3. KMP模式匹配算法 4. KMP算法的改进 5. KMP算法优化总结 6. 参考文献 1. 问题描述 在实际应用中,我们常会遇到这样的问题:判断一个较长的字符串(主串)中是否存在一个较短的字符串(子串),若存在,则返回匹配成功的索引。 阅读全文

posted @ 2018-06-24 20:58 沙_shine 阅读(205) 评论(0) 推荐(0)

摘要:1. 题目分析 这道题求输入数组的全排列,并且数组中的所有数字都不同。 2. 思路:交换生成 例如:输入【1,2,3】 步骤一:生成【1】 步骤二:先将2插入[1]的后面,生成【1,2】,然后将"2"前面的数字依次和"2"进行交换,生成【2,1】 步骤三:分别对【1,2】和【2,1】进行第二步的操作 阅读全文

posted @ 2018-05-31 17:14 沙_shine 阅读(174) 评论(0) 推荐(0)

摘要:主要按照以下思路进行介绍: 1. 拓扑排序 2. Course Schedule II题目分析 3. AC代码(C++) 1. 拓扑排序 摘自维基百科: 在图论中,由一个有向无环图(DAG, Directed Acyclic Graph)的顶点组成的序列,当且仅当满足下列条件时,称为该图的一个拓扑排 阅读全文

posted @ 2018-05-22 22:34 沙_shine 阅读(218) 评论(0) 推荐(0)

摘要:题目链接:https://leetcode.com/problems/gas-station/description/ There are N gas stations along a circular route, where the amount of gas at station i is g 阅读全文

posted @ 2018-04-10 23:19 沙_shine 阅读(239) 评论(0) 推荐(0)

摘要: 阅读全文

posted @ 2018-01-12 10:43 沙_shine 阅读(183) 评论(0) 推荐(0)

摘要:1. char 到 string char c = 'j'; stringstream stream; stream << c; string str = stream.str(); //这里str="j",char类型转换为string类型 2. char* 到 string 这里假设我们要将一个 阅读全文

posted @ 2017-12-28 16:15 沙_shine 阅读(1553) 评论(0) 推荐(0)

摘要:今天,试着做了一下LeetCode OJ上面的第375道题:Guess Number Higher or Lower II 原题链接:https://leetcode.com/problems/guess-number-higher-or-lower-ii/ 具体题目如下: We are playi 阅读全文

posted @ 2017-01-04 23:05 沙_shine 阅读(276) 评论(0) 推荐(0)

摘要:原题链接:https://leetcode.com/problems/symmetric-tree/ 题目如下: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center) 阅读全文

posted @ 2017-01-04 21:00 沙_shine 阅读(119) 评论(0) 推荐(0)

摘要:这是Leet Code OJ上面的一道题,关于求从上到下的最小路径。 这是原题链接:https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to bottom. Each 阅读全文

posted @ 2016-12-29 17:09 沙_shine 阅读(180) 评论(0) 推荐(0)