随笔分类 -  LeetCode

上一页 1 2 3

[LeetCode] 252. Meeting Rooms
摘要:这道题可以直接暴力解决,看看每个interval是不是和剩余的interval有重复。但是还有一种更优化的方法,先对起始时间排序,然后看每一个end的时间是不是比前一个的start时间早。 python笔记, 1. sorted function会create一个新的list,但是<my_list> 阅读全文

posted @ 2019-03-14 11:21 codingEskimo 阅读(114) 评论(0) 推荐(0)

[LeetCode] 6. ZigZag Conversion
摘要:这道题其实有两个思路 思路一:按顺序把每个字母分配到对应的行,再把行联接起来。具体是用一个string array来代表每一行,用一个current_row来记住现在的行数,然后用go记住方向,向下就是+1,向上就是-1,这样可以不停的运算更新current_row, 在顶行和底行反转go。 思路二 阅读全文

posted @ 2018-09-13 11:14 codingEskimo 阅读(101) 评论(0) 推荐(0)

[LeetCode] 5. Longest Palindromic Substring
摘要:这道题可以用动态规划,但是其实中心枚举更直接并符合逻辑,需要注意的是,以每一个字母为中心查找最大的Palindromic string的时候是有两种情况,第一种是以这个单一字母为中心(aba),第二个是以这个和下一个字母一起为中心(abba)。 阅读全文

posted @ 2018-09-13 09:30 codingEskimo 阅读(86) 评论(0) 推荐(0)

[LeetCode] 24. Swap Nodes in Pairs
摘要: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 阅读全文

posted @ 2018-03-27 10:23 codingEskimo 阅读(125) 评论(0) 推荐(0)

[LeetCode] Merge K Sorted Lists
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 时间复杂度 O(nlogk)思路: 这道题其实有三种做法,第一种是priorityQueue,第二种是 阅读全文

posted @ 2018-03-27 09:02 codingEskimo 阅读(113) 评论(0) 推荐(0)

[LeetCode][LintCode] Add Two Numbers
摘要: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 阅读全文

posted @ 2018-02-21 12:50 codingEskimo 阅读(127) 评论(0) 推荐(0)

[LeetCode][LintCode] Two Sum
摘要:思路: 这道题因为只有一对,所以可以用hashmap,需要注意的是,数字可能有重复, eg.[1,2,2,3,4] target = 4. 所以最好的办法就是把剩下的放进去。 这样如果有重复,没关系,把现在的index和已经放进去的index返回即可。 阅读全文

posted @ 2018-02-21 11:44 codingEskimo 阅读(95) 评论(0) 推荐(0)

[LeetCode] 104. Maximum Depth of Binary Tree
摘要:Good reference for all tree problem https://sites.google.com/site/jennyshelloworld/company-blog/chapter-3 binary-tree-divide-conquer Analysis: Here we 阅读全文

posted @ 2017-03-12 02:48 codingEskimo 阅读(104) 评论(0) 推荐(0)

[LeetCode] 28. Implement strStr
摘要: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 阅读全文

posted @ 2017-03-12 00:55 codingEskimo 阅读(151) 评论(0) 推荐(0)

Subsets II
摘要: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 阅读全文

posted @ 2016-08-08 09:19 codingEskimo 阅读(129) 评论(0) 推荐(0)

Subsets
摘要:Given a set of distinct integers, return all possible subsets. 这是一道排列与组合的问题, 对于这种题目就是求所有的方案,其中90%是用搜索, 而搜素的题目90%会用到递归。 这类题目的模版 1)把现在结果加进去 2)用for loop做 阅读全文

posted @ 2016-08-08 08:27 codingEskimo 阅读(175) 评论(0) 推荐(0)

Merge Sorted Array
摘要: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 阅读全文

posted @ 2016-08-03 11:16 codingEskimo 阅读(176) 评论(0) 推荐(0)

[LeetCode] 137. Single Number II
摘要: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 阅读全文

posted @ 2016-07-05 10:59 codingEskimo 阅读(179) 评论(0) 推荐(0)

[LeetCode] 136. Single Number
摘要: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 阅读全文

posted @ 2016-07-05 08:49 codingEskimo 阅读(134) 评论(0) 推荐(0)

[LeetCode] 3. Longest Substring Without Repeating Characters
摘要:首先看一下只需要return 长度的解法: public class Solution { public int lengthOfLongestSubstring(String s) { /*** * Basic idea: N(o^2): for each character, continue 阅读全文

posted @ 2015-12-10 13:06 codingEskimo 阅读(128) 评论(0) 推荐(0)

[LeetCode] 2. Add Two Numbers
摘要:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solu 阅读全文

posted @ 2015-12-09 14:10 codingEskimo 阅读(162) 评论(0) 推荐(0)

[LeetCode] 1. Two Sum
摘要: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 阅读全文

posted @ 2015-12-09 11:34 codingEskimo 阅读(107) 评论(0) 推荐(0)

[LeetCode] 206. Reverse Linked List
摘要:/** * Definition for ListNode. * public class ListNode { * int val; * ListNode next; * ListNode(int val) { * this.val = val; * this.next = null; * } * 阅读全文

posted @ 2015-12-01 09:54 codingEskimo 阅读(108) 评论(0) 推荐(0)

上一页 1 2 3

导航