
算法
wishingweed
这个作者很懒,什么都没留下…
展开
-
sunday 算法
SUNDAY 算法描述:字符串查找算法中,最著名的两个是KMP算法(Knuth-Morris-Pratt)和BM算法(Boyer-Moore)。两个算法在最坏情况下均具有线性的查找时间。但是在实用上,KMP算法并不比最简单的c库函数strstr()快多少,而BM算法则往往比KMP算法快上3-5倍。但是BM算法还不是最快的算法,这里介绍一种比BM算法更快一些的查找算法。例如我们要在"转载 2014-12-01 14:36:30 · 406 阅读 · 0 评论 -
count and say leetcode c++
pay attention to n and the string.it is easy to understand the code below.class Solution {public: string countAndSay(int n) { // Start typing your C/C++ solution below // DO原创 2014-12-02 23:40:41 · 517 阅读 · 0 评论 -
leetcode gas station
转载自felix博客园原题如下Gas StationThere are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[转载 2014-12-04 14:00:08 · 478 阅读 · 0 评论 -
leetcode contains duplicate III
基本就是遍历的过程中不断的用hash表进行判断,然后不断的维持着这个仍然在范围内的集合。class Solution {public: bool containsNearbyAlmostDuplicate(vector& nums, int k, int t) { map m; int j = 0; for (int i = 0; i转载 2015-10-26 21:22:04 · 347 阅读 · 0 评论 -
Contains Duplicate leetcode
easy problempublic class Solution { public boolean containsDuplicate(int[] nums) { if(nums.length<2) return false; Arrays.sort(nums); for(int i = 1;i<nums.lengt原创 2015-10-25 22:55:31 · 345 阅读 · 0 评论 -
dupicateII leetcode
map是一个接口而hashmap是它的一种实现方式for this problem, if you use eclipse,you will find that we need a () after the fucthion "new";another should be pay attention is when I use eclipse as the edcitior原创 2015-10-25 23:28:07 · 388 阅读 · 0 评论 -
Implement Queue using Stacks leetcode
This is really a classic problem, no more word need for this.class MyQueue { Stack stack1 = new Stack(); Stack stack2 = new Stack(); // Push element x to the back of queue. public void push原创 2015-10-30 15:39:30 · 314 阅读 · 0 评论 -
move zeros leetcode
Just use the thought of Bubble sort.I think it would have an O(n) algriothm, I would try it later.public class Solution { public void moveZeroes(int[] nums) { for(int j = 0;j < nums.length原创 2015-10-30 16:50:29 · 488 阅读 · 0 评论