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. compilation与编译

    关于本配置节的内容不算多,但关于ASP.NET编译的内容还是有一点的,鄙人认为只是了解一下即可,主要影响到部署. 在 App_Code 文件夹中使用多种编程语言 因为 App_Code 文件夹中的源代 ...

  2. Git 获取文件操作

    1. 在本地新建存放源代码的文件夹: 2. 进入文件夹下,右击选择 Git Bash Here ,弹出git命令行窗口: 3. 运行指定 git init,初始化git: 4. git  remote ...

  3. jsp页面显示问题

    一.在jsp页面的表格中,如果有表格中的某一个元素 内容太长,需要截取显示,方法如下: <%@ taglib prefix="fn" uri="http://jav ...

  4. MyEclipse或者Eclipse内存溢出问题

    对于一些项目,我们经常会遇到内存溢出的问题,这个时候我们就需要进行设置JDK的各个内存的大小了. 如果是运行项目以后出现问题的话,那么主要还是jdk或者是tomcat的内存问题,至于网上说的xxx.i ...

  5. ABP之Javascript生成

    还是服务 在调试SimpleTaskSystem的AngularJs demo时,一开始我只看到对服务的应用. app.controller(controllerId, [ '$scope', 'ab ...

  6. Apache Lucene(全文检索引擎)—创建索引

    目录 返回目录:http://www.cnblogs.com/hanyinglong/p/5464604.html 本项目Demo已上传GitHub,欢迎大家fork下载学习:https://gith ...

  7. css知多少(12)——目录

    <css知多少>系列就此完结了.常来光顾的朋友可能会觉得突然:css的知识点还有很多,怎么突然就完了,还没讲完呢?这样说是对的.不过凡事都有一个定位,如果盲目求多,定位模糊,那样就没有目的 ...

  8. 期待已久的2013年度最佳 jQuery 插件揭晓

    让人期待已久的2013年度最佳 jQuery 插件揭晓了.在过去的一年里,有很多很多的 jQuery 插件发布出来,而这里文章列出的这些插件从提供的功能更角度来看是其中的佼佼者.相信这些优秀的 jQu ...

  9. 探讨webapp的SEO难题(上)

    前言 网络蜘蛛无法解析javascript,至少百度是不能的,神马搜索差的更远,而我们的webapp的渲染展示完全由javascript驱动 所以蜘蛛访问webapp页面会得到一个白页面,比如,我们期 ...

  10. 显示快照监控:/SDF/MON

    透过SE38运行程序/SDF/MON,可以显示屏幕的监控快照: