<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rui Chen on Medium]]></title>
        <description><![CDATA[Stories by Rui Chen on Medium]]></description>
        <link>https://medium.com/@ruirui_24576?source=rss-bb5ecfd90536------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gSvOMMzoMz98skpN.</url>
            <title>Stories by Rui Chen on Medium</title>
            <link>https://medium.com/@ruirui_24576?source=rss-bb5ecfd90536------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:19:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ruirui_24576/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[21. Merge Two Sorted Lists[recursive][mergesort][list]]]></title>
            <link>https://medium.com/@ruirui_24576/21-merge-two-sorted-lists-recursive-mergesort-list-9b0a10ada21d?source=rss-bb5ecfd90536------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b0a10ada21d</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rui Chen]]></dc:creator>
            <pubDate>Sun, 29 Oct 2017 15:20:15 GMT</pubDate>
            <atom:updated>2017-10-29T15:20:15.710Z</atom:updated>
            <content:encoded><![CDATA[<p>Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.</p><h4><strong>Java</strong></h4><pre>/**<br> * Definition for singly-linked list.<br> * public class ListNode {<br> *     int val;<br> *     ListNode next;<br> *     ListNode(int x) { val = x; }<br> * }<br> */<br>class Solution {<br>    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {<br>        if(l1 == null){<br>            return l2;<br>        }<br>        if(l2 == null){<br>            return l1;<br>        }<br>        <br>        ListNode mergedhead;<br>        <br>        if(l1.val&lt;l2.val){<br>            mergedhead = l1;<br>            mergedhead.next = mergeTwoLists(l1.next,l2);<br>        }<strong>else</strong>{<br>            mergedhead = l2;<br>            mergedhead.next = mergeTwoLists(l1,l2.next);<br>        }<br>        return mergedhead;<br>    }<br>}</pre><p>but when write code like this:</p><pre>/**<br> * Definition for singly-linked list.<br> * public class ListNode {<br> *     int val;<br> *     ListNode next;<br> *     ListNode(int x) { val = x; }<br> * }<br> */<br>class Solution {<br>    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {<br>        if(l1 == null){<br>            return l2;<br>        }<br>        if(l2 == null){<br>            return l1;<br>        }<br>        <br>        ListNode mergedhead;<br>        <br>        if(l1.val&lt;l2.val){<br>            mergedhead = l1;<br>            mergedhead.next = mergeTwoLists(l1.next,l2);<br>        }<br>        <strong>if(l1.val&gt;=l2.val)</strong>{<br>            mergedhead = l2;<br>            mergedhead.next = mergeTwoLists(l1,l2.next);<br>        }<br>        return mergedhead;<br>    }<br>}</pre><p>it will give me compile error:</p><pre>Line 28: error: variable mergedhead might not have been initialized</pre><h4>Python</h4><pre># Definition for singly-linked list.<br># class ListNode(object):<br>#     def __init__(self, x):<br>#         self.val = x<br>#         self.next = None</pre><pre>class Solution(object):<br>    def mergeTwoLists(self, l1, l2):<br>        &quot;&quot;&quot;<br>        :type l1: ListNode<br>        :type l2: ListNode<br>        :rtype: ListNode<br>        <br>        &quot;&quot;&quot;<br>        if not l1:<br>            return l2<br>        if not l2:<br>            return l1<br>        <br>        if l1.val&lt;l2.val:<br>            l1.next = self.mergeTwoLists(l1.next,l2)<br>            return l1<br>        else:<br>            l2.next = self.mergeTwoLists(l1,l2.next)<br>            return l2</pre><p>Other excellent answers:</p><pre># iteratively<br>def mergeTwoLists1(self, l1, l2):<br>   <strong> dummy = cur = ListNode(0)</strong><br>    while l1 and l2:<br>        if l1.val &lt; l2.val:<br>            cur.next = l1<br>            l1 = l1.next<br>        else:<br>            cur.next = l2<br>            l2 = l2.next<br>        cur = cur.next<br>    cur.next = l1 or l2<br>    return <strong>dummy.next</strong></pre><pre># recursively    <br>def mergeTwoLists2(self, l1, l2):<br>    <strong>if not l1 or not l2:<br>        return l1 or l2</strong><br>    if l1.val &lt; l2.val:<br>        l1.next = self.mergeTwoLists(l1.next, l2)<br>        return l1<br>    else:<br>        l2.next = self.mergeTwoLists(l1, l2.next)<br>        return l2</pre><pre><br># in-place, iteratively        <br>def mergeTwoLists(self, l1, l2):<br><strong>    if None in (l1, l2):<br>        return l1 or l2</strong><br>    dummy = cur = ListNode(0)<br>    dummy.next = l1<br>    while l1 and l2:<br>        if l1.val &lt; l2.val:<br>            l1 = l1.next<br>        else:<br>            nxt = cur.next<br>            cur.next = l2<br>            tmp = l2.next<br>            l2.next = nxt<br>            l2 = tmp<br>        cur = cur.next<br>    cur.next = l1 or l2<br>    return dummy.next</pre><p>something I do not know before:</p><pre>print(None or 1)<br>&gt;&gt;1</pre><pre>if not a or not b:<br>    print(a or b)</pre><pre><strong>equals to:</strong></pre><pre>if None in (a,b):<br>    print(a or b)</pre><p>Some Interesting things about python:</p><p><strong>None, False, “”, 0, [], {}, ()</strong></p><pre>0 is None<br>Out[15]: False</pre><pre><strong>None is None<br>Out[16]: True</strong></pre><pre>&quot;&quot; is None<br>Out[17]: False</pre><pre>[] is None<br>Out[18]: False</pre><pre>{} is None<br>Out[19]: False</pre><pre>() is None<br>Out[20]: False</pre><pre>False is None<br>Out[21]: False</pre><pre>-------------------------------------------------------------------</pre><pre>not []<br>Out[22]: True</pre><pre>not ()<br>Out[23]: True</pre><pre>not None<br>Out[24]: True</pre><pre>not {}<br>Out[25]: True</pre><pre>not 0<br>Out[26]: True</pre><pre>not &quot;&quot;<br>Out[27]: True</pre><pre>&gt;&gt;&gt; x = 0<br>&gt;&gt;&gt; not x<br>True<br>&gt;&gt;&gt; x = [0]         # You don&#39;t want to fall in this one.<br>&gt;&gt;&gt; not x<br>False</pre><p><strong>for…[if]…</strong></p><pre>&gt;&gt;&gt; a=[12,3,4,6,7,13,21]  <br>&gt;&gt;&gt; newList =[x for x in a]  <br>&gt;&gt;&gt; newList  <br>[12,3,4,6,7,13,21]  <br>&gt;&gt;&gt; <strong>newList2 =[x for x in a if x%2==0] </strong> <br>&gt;&gt;&gt; newList2  <br>[12,4,6]</pre><p><strong>for/while…else</strong></p><pre>for i in range(10):<br>        print(i)<br>        if i==3:<br>            break<br>else:<br>     print(&#39;not meeting break&#39;)</pre><pre>0<br>1<br>2<br>3</pre><pre>----------------------------------------------------------------</pre><pre>&gt;&gt;&gt; for i in range(10):<br> print(i)<br> if i==10:<br>  break<br>else:<br> print(&#39;not meeting break&#39;)<br> <br>0<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>not meeting break</pre><p><strong>range or xrange</strong></p><p>range will create a list. but xrange will not. So xrange is better because it will not create a large space in the beginning.</p><pre>&gt;&gt;&gt; range(5) <br>[0, 1, 2, 3, 4] <br>&gt;&gt;&gt; range(1,5) <br>[1, 2, 3, 4] <br>&gt;&gt;&gt; range(0,6,2)<br>[0, 2, 4]</pre><pre>-----------------------------------------------------------------</pre><pre>&gt;&gt;&gt; xrange(5)<br>xrange(5)<br>&gt;&gt;&gt; list(xrange(5))<br>[0, 1, 2, 3, 4]<br>&gt;&gt;&gt; xrange(1,5)<br>xrange(1, 5)<br>&gt;&gt;&gt; list(xrange(1,5))<br>[1, 2, 3, 4]<br>&gt;&gt;&gt; xrange(0,6,2)<br>xrange(0, 6, 2)<br>&gt;&gt;&gt; list(xrange(0,6,2))<br>[0, 2, 4]</pre><p><strong>Difference between</strong> is (compare the object) <strong>and</strong> ==/eq() (compare the value of object)</p><pre>&gt;&gt;&gt; list1 = [1, 2, 3]<br>&gt;&gt;&gt; list2 = [1, 2, 3]<br>&gt;&gt;&gt; list1==list2<br>True<br>&gt;&gt;&gt; list1 is list2<br>False</pre><p>a==b==c</p><p>”5== len(a)== len(b)“ is ”5== len(a) and len(a)==len(b)“</p><pre>a = 1</pre><pre>b = 2</pre><pre>c = 2</pre><pre>a==b==c<br>Out[34]: False</pre><pre>2==b==c<br>Out[35]: True</pre><pre>True == c<br>Out[36]: False</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b0a10ada21d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[20.[stack][queue][deque]/[list][set]]]></title>
            <link>https://medium.com/@ruirui_24576/leetcode-exercise-ee5c2fa3b257?source=rss-bb5ecfd90536------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee5c2fa3b257</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rui Chen]]></dc:creator>
            <pubDate>Sat, 21 Oct 2017 11:45:27 GMT</pubDate>
            <atom:updated>2017-10-29T15:21:48.843Z</atom:updated>
            <content:encoded><![CDATA[<p>Given a string containing just the characters &#39;(&#39;, &#39;)&#39;, &#39;{&#39;, &#39;}&#39;, &#39;[&#39; and &#39;]&#39;, determine if the input string is valid.The brackets must close in the correct order, &quot;()&quot; and &quot;()[]{}&quot; are all valid but &quot;(]&quot; and &quot;([)]&quot; are not.</p><p>Python code：</p><pre>class Solution(object):<br>    def isValid(self, s):<br>        dict = {&#39;}&#39;:&#39;{&#39;,&#39;]&#39;:&#39;[&#39;,&#39;)&#39;:&#39;(&#39;}<br>        stack = []<br>        for i in s:<br>            if i in dict.values():<br>                stack.append(i)<br>            elif i in dict.keys():<br>                if stack==[] or <strong>stack.pop()!</strong>=dict[i]:<br>                    return False<br>            else:<br>                return False<br>        if len(stack)!=0:<br>            return False<br>        return True</pre><p>About Python</p><pre><strong>&gt;&gt;&gt; </strong>a = [66.25, 333, 333, 1, 1234.5]<br><strong>&gt;&gt;&gt; </strong>print a.count(333), a.count(66.25), a.count(&#39;x&#39;)<br>2 1 0<br><strong>&gt;&gt;&gt; </strong>a.insert(2, -1)<br><strong>&gt;&gt;&gt; </strong>a.append(333)<br><strong>&gt;&gt;&gt; </strong>a<br>[66.25, 333, -1, 333, 1, 1234.5, 333]<br><strong>&gt;&gt;&gt; </strong>a.index(333)<br>1<br><strong>&gt;&gt;&gt; </strong>a.remove(333)<br><strong>&gt;&gt;&gt; </strong>a<br>[66.25, -1, 333, 1, 1234.5, 333]<br><strong>&gt;&gt;&gt; </strong>a.reverse()<br><strong>&gt;&gt;&gt; </strong>a<br>[333, 1234.5, 1, 333, -1, 66.25]<br><strong>&gt;&gt;&gt; </strong>a.sort()<br><strong>&gt;&gt;&gt; </strong>a<br>[-1, 1, 66.25, 333, 333, 1234.5]<br><strong>&gt;&gt;&gt; </strong>a.pop()<br>1234.5<br><strong>&gt;&gt;&gt; </strong>a<br>[-1, 1, 66.25, 333, 333]</pre><p>Using list as Stack</p><pre><strong>&gt;&gt;&gt; </strong>stack = [3, 4, 5]<br><strong>&gt;&gt;&gt; </strong>stack.append(6)<br><strong>&gt;&gt;&gt; </strong>stack.append(7)<br><strong>&gt;&gt;&gt; </strong>stack<br>[3, 4, 5, 6, 7]<br><strong>&gt;&gt;&gt; </strong>stack.pop()<br>7<br><strong>&gt;&gt;&gt; </strong>stack<br>[3, 4, 5, 6]<br><strong>&gt;&gt;&gt; </strong>stack.pop()<br>6<br><strong>&gt;&gt;&gt; </strong>stack.pop()<br>5<br><strong>&gt;&gt;&gt; </strong>stack<br>[3, 4]</pre><p>using list as queues</p><pre><strong>&gt;&gt;&gt; from</strong> <strong>collections</strong> <strong>import</strong> deque<br><strong>&gt;&gt;&gt; </strong>queue = deque([&quot;Eric&quot;, &quot;John&quot;, &quot;Michael&quot;])<br><strong>&gt;&gt;&gt; </strong>queue.append(&quot;Terry&quot;)           <em># Terry arrives</em><br><strong>&gt;&gt;&gt; </strong>queue.append(&quot;Graham&quot;)          <em># Graham arrives</em><br><strong>&gt;&gt;&gt; </strong>queue.popleft()                 <em># The first to arrive now leaves</em><br>&#39;Eric&#39;<br><strong>&gt;&gt;&gt; </strong>queue.popleft()                 <em># The second to arrive now leaves</em><br>&#39;John&#39;<br><strong>&gt;&gt;&gt; </strong>queue                           <em># Remaining queue in order of arrival</em><br>deque([&#39;Michael&#39;, &#39;Terry&#39;, &#39;Graham&#39;])</pre><p>Java code using stack：</p><pre>class Solution {<br>    public boolean isValid(String s) {<br>        Stack&lt;Character&gt; stack = new Stack&lt;Character&gt;();<br>        for<strong>(char c:s.toCharArray())</strong>{<br>            if(c==&#39;{&#39;)<br>                stack.push(&#39;}&#39;);<br>            else if(c==&#39;[&#39;)<br>                stack.push(&#39;]&#39;);<br>            else if(c==&#39;(&#39;)<br>                stack.push(&#39;)&#39;);<br>            else if(stack.isEmpty()||stack.pop()!=c){<br>                return false;<br>            }<br>            <br>        }<br>        return stack.isEmpty();<br>        <br>    }<br>}</pre><p>Java code using deque</p><pre>class Solution {<br>    public boolean isValid(String s) {<br>        Deque&lt;Character&gt; deque = new LinkedList&lt;Character&gt;();<br>        for(char c:s.toCharArray()){<br>            if(c==&#39;{&#39;)<br>                deque.addFirst(&#39;}&#39;);<br>            else if(c==&#39;[&#39;)<br>                deque.addFirst(&#39;]&#39;);<br>            else if(c==&#39;(&#39;)<br>                deque.addFirst(&#39;)&#39;);<br>            else if(deque.isEmpty()||deque.pollFirst()!=c){<br>                return false;<br>            }<br>            <br>        }<br>        return deque.isEmpty();<br>        <br>    }<br>}</pre><p>About Java Stack</p><p>Methods</p><p>— <strong>boolean empty()</strong> return true if stack is empty</p><p>— <strong>Object peek()</strong> return the top object of stack without deleting it</p><p>— <strong>Object pop()</strong> return the top object of stack and delete it from the stack</p><p>—<strong> Object push(Object element) </strong>push object into the top of stack</p><p>—<strong> int search(Object element) </strong>return the index of object, base on 1</p><p>if there are multiple same item, return object closest to the top of stack</p><p>— try { showpop(st); } catch (<strong>EmptyStackException e</strong>) { System.out.println(“empty stack”); } } } <strong>instead of returning null</strong></p><p>— Stack&lt;&gt; stack = new Stack&lt;&gt;();<strong>&lt;&gt; →Integer/Character</strong></p><p>example from <a href="http://blog.csdn.net/a19881029/article/details/9408649">http://blog.csdn.net/a19881029/article/details/9408649</a>:</p><pre>public class Test {<br> public static void main(String[] args) {<br>  Stack&lt;String&gt; s = new Stack&lt;String&gt;();<br>  System.out.println(&quot;------isEmpty&quot;);<br>  System.out.println(s.isEmpty());<br>  System.out.println(&quot;------push&quot;);<br>  s.push(&quot;1&quot;);<br>  s.push(&quot;2&quot;);<br>  s.push(&quot;3&quot;);<br>  Test.it(s);<br>  System.out.println(&quot;------pop&quot;);<br>  String str = s.pop();<br>  System.out.println(str);<br>  Test.it(s);<br>  System.out.println(&quot;------peek&quot;);<br>  str = s.peek();<br>  System.out.println(str);<br>  Test.it(s);<br>  System.out.println(&quot;------search&quot;);<br>  int i = s.search(&quot;2&quot;);<br>  System.out.println(i);<br>  i = s.search(&quot;1&quot;);<br>  System.out.println(i);<br>  i = s.search(&quot;none&quot;);<br>  System.out.println(i);<br> }<br> <br> public static void it(Stack&lt;String&gt; s){<br>  System.out.print(&quot;iterator:&quot;);<br>  Iterator&lt;String&gt; it = s.iterator();<br>  while(it.hasNext()){<br>   System.out.print(it.next()+&quot;;&quot;);<br>  }<br>  System.out.print(&quot;\n&quot;);<br> }<br>}</pre><p>answer:</p><pre>------isEmpty<br>true          <br>------push<br>iterator:1;2;3;  <br>------pop<br>3  <br>iterator:1;2;<br>------peek<br>2  <br>iterator:1;2;<br>------search    <br>1  --base on one<br>2  --distance to the top of stack --&gt; 2-1=1<br>-1  --there is no such thing in the stack</pre><p>Stack Traversal(<a href="http://lavasoft.blog.51cto.com/62575/181781/">http://lavasoft.blog.51cto.com/62575/181781/</a>):</p><pre>public class TestStack { <br>        public static void main(String[] args) { <br>                Stack&lt;Integer&gt; s = new Stack&lt;Integer&gt;(); <br>                for (int i = 0; i &lt; 10; i++) { <br>                        s.push(i); <br>                } <br>                //集合遍历方式,不会清空 <br>                for (Integer x : s) { <br>                        System.out.println(x); <br>                } <br>                System.out.println(&quot;------1-----&quot;); <br>                //栈弹出遍历方式，遍历完清空<br>//                while (s.peek()!=null) {     //不健壮的判断方式，容易抛异常，正确写法是下面的 <br>                while (!s.empty()) { <br>                        System.out.println(s.pop()); <br>                } <br>                System.out.println(&quot;------2-----&quot;); <br>                //错误的遍历方式 <br>//                for (Integer x : s) { <br>//                        System.out.println(s.pop()); <br>//                } <br>        } <br>}<br>--------------------------------------------------------------------</pre><pre>/**<br>     * 通过快速访问遍历Stack<br>     */<br>    public static void iteratorThroughRandomAccess(List list) {<br>        String val = null;<br>        for (int i=0; i&lt;list.size(); i++) {<br>            val = (String)list.get(i);<br>            System.out.print(val+&quot; &quot;);<br>        }<br>        System.out.println();<br>    }</pre><pre>/**<br>     * 通过迭代器遍历Stack<br>     */<br>    public static void iteratorThroughIterator(List list) {</pre><pre>String val = null;<br>        for(Iterator iter = list.iterator(); iter.hasNext(); ) {<br>            val = (String)iter.next();<br>            System.out.print(val+&quot; &quot;);<br>        }<br>        System.out.println();<br>    }</pre><pre>}</pre><p>About Java queue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EngJ8JROcKIEOp49Kt7RoQ.png" /></figure><p>The <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html#offer(E)">offer</a> method inserts an element if possible, otherwise returning false. This differs from the <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html#add(E)">Collection.add</a> method, which can fail to add an element only by throwing an unchecked exception. The offer method is designed for use when failure is a normal, rather than exceptional occurrence, for example, in fixed-capacity (or &quot;bounded&quot;) queues.</p><p>The <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html#remove()">remove()</a> and <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html#poll()">poll()</a> methods remove and return the head of the queue. Exactly which element is removed from the queue is a function of the queue&#39;s ordering policy, which differs from implementation to implementation. The remove() and poll() methods differ only in their behavior when the queue is empty: the remove() method throws an exception, while the poll() method returns null.</p><p>The <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html#element()">element()</a> and <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html#peek()">peek()</a> methods return, but do not remove, the head of the queue.</p><p>Queue implementations generally<strong> do not allow insertion of null elements, </strong>although some implementations, such as <a href="http://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html">LinkedList</a>, do not prohibit insertion of null. Even in the implementations that permit it, <strong>null should not be inserted into a Queue, as null is also used as a special return value by the poll method to indicate that the queue contains no elements.</strong></p><p>example:</p><pre>package com.ljq.test;</pre><pre>import java.util.LinkedList;<br>import java.util.Queue;</pre><pre>public class QueueTest {<br>    public static void main(String[] args) {<br>        //add()和remove()方法在失败的时候会抛出异常(不推荐)<br>        Queue&lt;String&gt; queue = new LinkedList&lt;String&gt;();<br>        //添加元素<br>        queue.offer(&quot;a&quot;);<br>        queue.offer(&quot;b&quot;);<br>        queue.offer(&quot;c&quot;);<br>        queue.offer(&quot;d&quot;);<br>        queue.offer(&quot;e&quot;);<br>        for(String q : queue){<br>            System.out.println(q);<br>        }<br>        System.out.println(&quot;===&quot;);<br>        System.out.println(&quot;poll=&quot;+queue.poll()); //返回第一个元素，并在队列中删除<br>        for(String q : queue){<br>            System.out.println(q);<br>        }<br>        System.out.println(&quot;===&quot;);<br>        System.out.println(&quot;element=&quot;+queue.element()); //返回第一个元素 <br>        for(String q : queue){<br>            System.out.println(q);<br>        }<br>        System.out.println(&quot;===&quot;);<br>        System.out.println(&quot;peek=&quot;+queue.peek()); //返回第一个元素 <br>        for(String q : queue){<br>            System.out.println(q);<br>        }<br>        <br>    }<br>}</pre><p>Java about deque</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T3HGN3c--oHEQDodOG2ZRA.png" /></figure><p>— -boolean removeFirstOccurrence(Object o);</p><p>delete the first element which satisfies the condition(o==null ? e==null : o.equals(e)). it works then return true,no then false</p><p>— -boolean removeLastOccurrence(Object o);</p><p>delete the last element which satisfies the condition(o==null ? e==null : o.equals(e)). it works then return true,no then false</p><p>— -boolean contains(Object o);</p><p>— -public int size();</p><p>— -Iterator&lt;E&gt; iterator(); from head to tail</p><p>— -Iterator&lt;E&gt; descendingIterator(); from tail to head</p><p>Compare to Stack and queue:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*WDMTpdC4bCmCpq4ArWQULg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DF6BogDZ-kFIyLtnlek7sw.png" /></figure><p>example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6D9LX81txHHtz24s9dMJA.png" /></figure><p>About Python useful Programming Tools</p><p>filter(function, sequence) returns a sequence consisting of those items from the sequence for which function(item) is true.</p><pre><strong>&gt;&gt;&gt; def</strong> f(x): <strong>return</strong> x % 3 == 0 <strong>or</strong> x % 5 == 0<br><strong>...</strong><br><strong>&gt;&gt;&gt; </strong>filter(f, range(2, 25))<br>[3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24]</pre><p>map(function, sequence) calls function(item) for each of the sequence’s items and returns a list of the return values. For example, to compute some cubes:</p><pre><strong>&gt;&gt;&gt; def</strong> cube(x): <strong>return</strong> x*x*x<br><strong>...</strong><br><strong>&gt;&gt;&gt; </strong>map(cube, range(1, 11))<br>[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]</pre><p>More than one sequence may be passed</p><pre><strong>&gt;&gt;&gt; </strong>seq = range(8)<br><strong>&gt;&gt;&gt; def</strong> add(x, y): <strong>return</strong> x+y<br><strong>...</strong><br><strong>&gt;&gt;&gt; </strong>map(add, seq, seq)<br>[0, 2, 4, 6, 8, 10, 12, 14]</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee5c2fa3b257" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn hard!]]></title>
            <link>https://medium.com/@ruirui_24576/learn-hard-810ebf3a6778?source=rss-bb5ecfd90536------2</link>
            <guid isPermaLink="false">https://medium.com/p/810ebf3a6778</guid>
            <dc:creator><![CDATA[Rui Chen]]></dc:creator>
            <pubDate>Thu, 19 Oct 2017 03:23:33 GMT</pubDate>
            <atom:updated>2017-10-19T03:23:33.537Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn hard!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=810ebf3a6778" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>