摘要:这道题可以直接暴力解决,看看每个interval是不是和剩余的interval有重复。但是还有一种更优化的方法,先对起始时间排序,然后看每一个end的时间是不是比前一个的start时间早。 python笔记, 1. sorted function会create一个新的list,但是<my_list>
阅读全文
摘要:这道题其实有两个思路 思路一:按顺序把每个字母分配到对应的行,再把行联接起来。具体是用一个string array来代表每一行,用一个current_row来记住现在的行数,然后用go记住方向,向下就是+1,向上就是-1,这样可以不停的运算更新current_row, 在顶行和底行反转go。 思路二
阅读全文
摘要:这道题可以用动态规划,但是其实中心枚举更直接并符合逻辑,需要注意的是,以每一个字母为中心查找最大的Palindromic string的时候是有两种情况,第一种是以这个单一字母为中心(aba),第二个是以这个和下一个字母一起为中心(abba)。
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your a
阅读全文
摘要: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返回即可。
阅读全文
摘要:Good reference for all tree problem https://sites.google.com/site/jennyshelloworld/company-blog/chapter-3 binary-tree-divide-conquer Analysis: Here we
阅读全文
摘要:Notice 1. Input String always need to be check whether it is NULL; 2. For the conner cases, source is shorter than the target or target is empty, it c
阅读全文
摘要:Given a list of numbers that may has duplicate numbers, return all possible subsets class Solution { /** * @param S: A set of numbers. * @return: A li
阅读全文
摘要:Given a set of distinct integers, return all possible subsets. 这是一道排列与组合的问题, 对于这种题目就是求所有的方案,其中90%是用搜索, 而搜素的题目90%会用到递归。 这类题目的模版 1)把现在结果加进去 2)用for loop做
阅读全文
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array. Notice You may assume that A has enough space (size that is greater or eq
阅读全文
摘要:Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your al
阅读全文
摘要:There are two ways for the problem:1. Tradition: Setup a map or set.2. Bit operation: x ^ x = 0; so if the number keep XOR, the same ones will cancel
阅读全文
摘要:首先看一下只需要return 长度的解法: public class Solution { public int lengthOfLongestSubstring(String s) { /*** * Basic idea: N(o^2): for each character, continue
阅读全文
摘要:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solu
阅读全文
摘要:public class Solution { public int[] twoSum(int[] nums, int target) { /* Basic idea: Load the array into a hashMap with the value of each array elemen
阅读全文
摘要:/** * Definition for ListNode. * public class ListNode { * int val; * ListNode next; * ListNode(int val) { * this.val = val; * this.next = null; * } *
阅读全文