摘要: 用queue实现stack题目要求:Implement the following operationspush(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get... 阅读全文
posted @ 2015-06-13 06:59 xiaomaoliu 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 关于Trie的几种实现方式children node的存储1可以用hashmap来存储children,HashMap children, 优势是利用contains函数便于查找2用数组TrieNode[] children; 通过index来查找,最多也就26个char(认为忽略大小写)Searc... 阅读全文
posted @ 2015-06-03 06:33 xiaomaoliu 阅读(190) 评论(0) 推荐(0) 编辑
摘要: leetcode新题,另外似乎是L家面经题Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.... 阅读全文
posted @ 2015-05-28 06:53 xiaomaoliu 阅读(212) 评论(0) 推荐(0) 编辑
摘要: cc150 Question 11.2 Sort array of string that anagrams next to each other.(leetcode 也有类似题目)Solution 1: 借助Arrays.sort, 需要重写comparator。 1 public sta... 阅读全文
posted @ 2015-05-08 04:20 xiaomaoliu 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Binary Search:二分查找实现方式:recursive or iterative注意问题,终止循环条件,移动start,end时边界值,start = mid,end = midTemplate:1. 在排序的数组中找A[i] == i的index,有重复元素存在. (cc150 Ques... 阅读全文
posted @ 2015-05-05 08:11 xiaomaoliu 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 找binary tree中两个node第一个公共祖先。注意不一定是BST想法:p,q都在左子树,就branch left。如果都在right,就branch right。如果不在same side,就返回first common ancestor所以主要是在left subtree和right su... 阅读全文
posted @ 2015-05-04 11:42 xiaomaoliu 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 给定一个node,找inorder traversal 里下一个。最直接的想法是inorder遍历整个bst,然后在遍历的结果中查找。但是这样耗费多余的空间和时间。geeksforgeek(1)有parent指针在cc150上有很好的讲解三种情况:i 当前node的right != null, 则返... 阅读全文
posted @ 2015-05-03 13:35 xiaomaoliu 阅读(174) 评论(0) 推荐(0) 编辑