摘要:这道题可以直接暴力解决,看看每个interval是不是和剩余的interval有重复。但是还有一种更优化的方法,先对起始时间排序,然后看每一个end的时间是不是比前一个的start时间早。 python笔记, 1. sorted function会create一个新的list,但是<my_list>
阅读全文
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 时间复杂度 O(nlogk)思路: 这道题其实有三种做法,第一种是priorityQueue,第二种是
阅读全文
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai
阅读全文
摘要:思路: 这道题因为只有一对,所以可以用hashmap,需要注意的是,数字可能有重复, eg.[1,2,2,3,4] target = 4. 所以最好的办法就是把剩下的放进去。 这样如果有重复,没关系,把现在的index和已经放进去的index返回即可。
阅读全文
摘要:Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are s
阅读全文
摘要:There is a building of n floors. If an egg drops from the k th floor or above, it will break. If it's dropped from any floor below, it will not break.
阅读全文
摘要:A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but i
阅读全文
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim
阅读全文
摘要:Given a knight in a chessboard n * m (a binary matrix with 0 as empty and 1 as barrier). the knight initialze position is (0, 0) and he wants to reach
阅读全文
摘要:76. Longest Increasing Subsequence 116. Jump Game 603. Largest Divisible Subset 611. Knight Shortest Path 630. Knight Shortest Path II 116. Jump Game
阅读全文
摘要:This question is standard level BSF. From this question, we can see the best time to mark a node is the time when it is added to a queue.
阅读全文
摘要:Note: This is to count the level. At beginning, since there are so many zombies, we need to add all of them to the Queue to start with. It is differen
阅读全文
摘要:This is Matrix Problem which can be converted to BSF: Loop through each node, if it is island, find the edge. Inside the mark them all as sea. So it w
阅读全文
摘要:Only Path :判断是否只存在一个拓扑排序的序列 只需要保证队列中一直最多只有1个元素即可 tricky part:1) org has all the nodes. That is why each time there should only be 1 element in the que
阅读全文
摘要:Note: 1) For integer node 0~n, we don't need a hashmap, we can just use array to act like a map; 2) How to initial List[] is very important 3) We need
阅读全文
摘要:Topological Sorting is very important, almost every company has a question related to it. Goal: To find an proper order making the front nodes are ind
阅读全文
摘要:Note: BSF: if it needs to check the value, should check it when it is coming from Queue. The logic is most clear to do it there. This question is to a
阅读全文
摘要:This question is the same as Binary Tree Treverse in Level Order. Instead of a list, we need ListNode to remeber the result. The tricky part is that w
阅读全文
摘要:Similar to Binary Tree Level Order Travel, just need to add a flag to remeber the order. Change the order to opposite after the level is over.
阅读全文