August 7, 2015

周日玩这个算法, 看到Javascript Array模拟Deque, 非常喜欢, 想用C#数组也模拟; 看有什么新的经历. 试了四五种方法, 花时间研究C# SortedList class. Try to get some workout on the C# programming practice.

我的体会是代码写得太少,  要多读不同的代码, 多调试, 开阔对一个问题思考的思路和深度, 准确度, 实现能力.

1. Blog to read:

C# code implementation (double ended queue is implemented using C# LinkedList class):

https://github.com/jianminchen/slidingWindowMaximum/blob/master/slidingWindowMaximum1.cs

2. Blog to read

C# code implementation (C# does not have deque class, so using C# List<int>,

convert Python code implementation to C#, time limit exceeded)

Good workout on C# List<int>, and also, experience different style on removing head element if out of sliding window.

https://github.com/jianminchen/slidingWindowMaximum/blob/master/slidingWindowMaximu2.cs

3. Blog to read

Method A: naive solution, time complexity O(nw)

Method B: using Self-Balancing Tree (Time complexity: O(nk), need to write c# code)

4. blog:

http://n00tc0d3r.blogspot.ca/2013/04/sliding-window-maximum.html

Good comment about Deque:

We can use a Deque which allow insertions/deletions on both ends. For a Deque implemented by Circular Array/Bufferor Double Linked List, the basic insert/delete operations run in constant time.

discussion of using heap:

The first thought might be heap.

By maintaining a heap for all numbers in the window can give us a O(nlogw)-time solution, where

  • building up a heap for initial window takes time O(wlogw)
  • when window moves to the next number, each insertion and deletion take time O(logw) and there are n-w moves in total.
  • after updating the heap, findMax only takes time O(1) since we know the top of heap is the largest.

So, if w << n, the performance of this solution is good, close to O(n); but if w is not that small, say w = n/3 or n/4, the running time goes up to O(nlogn).

5. blog:

https://github.com/haoel/leetcode/commit/74d83796aa48cc55d7995b1f9e61db40759204bb

using C++ multiset in the above solution, so try to convert it to C# class using SortedList

https://github.com/jianminchen/slidingWindowMaximum/blob/master/slidingWindowMaximu5.cs

6. blog:

http://www.mamicode.com/info-detail-927510.html

convert Java Script code to C#; I spent over 12 months to try to be expert on Java Script, so much fun to read the Java Script code again, and enjoyed the blog about the analysis.

Others:

https://github.com/jianminchen/slidingWindowMaximum/blob/master/slidingWindowMaximu5.cs

Leetcode: sliding window maximum的更多相关文章

  1. [LeetCode] Sliding Window Maximum 滑动窗口最大值

    Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...

  2. 239. [LeetCode ]Sliding Window Maximum

    Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...

  3. leetcode面试准备:Sliding Window Maximum

    leetcode面试准备:Sliding Window Maximum 1 题目 Given an array nums, there is a sliding window of size k wh ...

  4. 【LeetCode】239. Sliding Window Maximum

    Sliding Window Maximum   Given an array nums, there is a sliding window of size k which is moving fr ...

  5. 【刷题-LeetCode】239. Sliding Window Maximum

    Sliding Window Maximum Given an array nums, there is a sliding window of size k which is moving from ...

  6. [LeetCode] Sliding Window Median 滑动窗口中位数

    Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

  7. [LeetCode] 239. Sliding Window Maximum 滑动窗口最大值

    Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...

  8. 【LeetCode】239. Sliding Window Maximum 解题报告(Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调递减队列 MultiSet 日期 题目地址:ht ...

  9. LeetCode题解-----Sliding Window Maximum

    题目描述: Given an array nums, there is a sliding window of size k which is moving from the very left of ...

随机推荐

  1. jQuery弹出美女大图片

    效果:http://hovertree.com/texiao/jqimg/2/ 效果图: 下载:http://hovertree.com/h/bjaf/jdaqepet.htm HTML代码: < ...

  2. JS进阶之原型

    之前有在自己的文章中谈到对象,而说到对象我们就不可避免的要扯到原型,并且原型也是我们必须得理解到位的一个点,那接下来我们就来聊一聊js的原型吧. JS中一切皆为对象,那么原型也是一种对象.所以它有对象 ...

  3. JavaScript进阶之this

    javascript的this,一个不知道究竟属于谁的东西 this是一个大利器,用好了就可以帮我们省掉很多事,然而事实上却总是让我们出错.自己就吃过很大的亏.现在咱们就来扒一扒this究竟是什么. ...

  4. 总结shell

    总结shell里面一些初学者不容易懂得点,因为我本身就是初学者,所以有一些知识点是不容易通过字面意思理解的,下面写在这里. (便于理解的一个方法就是举例子)举个例子就是哪些容易学,哪些不容易理解:丁是 ...

  5. ABP中使用Redis Cache(2)

    上一篇讲解了如何在ABP中使用Redis Cache,虽然能够正常的访问Redis,但是Redis里的信息无法同步更新.本文将讲解如何实现Redis Cache与实体同步更新.要实现数据的同步更新,我 ...

  6. 基于SSH框架的学生公寓管理系统的质量属性

    系统名称:学生公寓管理系统 首先介绍一下学生公寓管理系统,在学生公寓管理方面,针对学生有关住宿信息问题进行管理,学生公寓管理系统主要包含了1)学生信息记录:包括学号.姓名.性别.院系.班级:2)住宿信 ...

  7. java集合-补充HashMapJDK1.8

    在Java 8 之前,HashMap和其他基于map的类都是通过链地址法解决冲突,它们使用单向链表来存储相同索引值的元素.在最坏的情况下,这种方式会将HashMap的get方法的性能从O(1)降低到O ...

  8. AngularJS学习笔记(1) - AngularJS入门

    什么是AngularJS? AngularJS是建立在jQuery的一个轻量级版本之上的MVC框架.MVC将业务逻辑代码和视图.模型相分离.AngularJS提供的所有功能都可以通过使用JavaScr ...

  9. SharePoint 2013 搜索高级配置(Search Scope)

    前言:SharePoint 2013集成了Fast Search,而后在配置上与2010及之前版本都有一些区别,如果需要开启搜索的文档,请参考我之前写的博客,博客地址附后.下面,我们开始了解下,Sha ...

  10. Clion 跨平台的C++ IDE

    CLion 是 JetBrains 推出的全新的 C/C++ 跨平台集成开发环境. 正式版本已经发出,目前是1.0.1 http://www.jetbrains.com/clion/ http://b ...