摘要: 字符串匹配的问题应该最先想到dp, 主要还是说一下动态规划的方法。跟Regular Expression Matching一样,还是维护一个假设我们维护一个布尔数组res[i],代表s的前i个字符和p的前j个字符是否匹配(这里因为每次i的结果只依赖于j-1的结果,所以不需要二维数组,只需要一个一维数 阅读全文
posted @ 2017-08-19 20:40 apanda009 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 第一想法是用HashSet<ListNode>, A list先遍历,存HashSet,然后B list遍历,发现ListNode存在就返回。但是这个方法不满足O(1)memory的要求。 再想了一会儿,略微受了点提醒,发现可以利用这个O(n) time做文章。这个条件方便我们scan list几次 阅读全文
posted @ 2017-08-19 18:20 apanda009 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 关于链表的题, 画图看看需要那几个节点, 一般都是接头节点(用作标记) 和遍历节点, 遍历的时候要判空, head.next != null 前一定要判head != null, 将尾节点置为空! 阅读全文
posted @ 2017-08-19 15:39 apanda009 阅读(92) 评论(0) 推荐(0) 编辑
摘要: The idea is try to replace every "++" in the current string s to "--" and see if the opponent has the chance to win or not, if the opponent is guarant 阅读全文
posted @ 2017-08-19 10:43 apanda009 阅读(144) 评论(0) 推荐(0) 编辑
摘要: You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". The g... 阅读全文
posted @ 2017-08-19 09:09 apanda009 阅读(126) 评论(0) 推荐(0) 编辑