随笔分类 -  Leetcode

Solutions for the problems on Leetcode
摘要:问题: https://leetcode.com/problems/add-two-numbers-ii/#/description 思路:该题与“415. Add Strings”类似,都需要先将原来的数字序列翻转,然后就转化成了跟“2. Add Two Numbers”类似的问题,进而就容易解决 阅读全文
posted @ 2017-04-26 18:11 爪哇国臣民 阅读(181) 评论(0) 推荐(0)
摘要:问题: https://leetcode.com/problems/01-matrix/#/description 基本思路:广度优先遍历,根据所有最短距离为N的格找到所有距离为N+1的格,直到所有的格都找到了最短距离。 具体步骤: 首先初始化矩阵,值为0的格其最短距离也是0,保持不变;值为1的格是 阅读全文
posted @ 2017-04-25 01:10 爪哇国臣民 阅读(472) 评论(0) 推荐(0)
摘要:Problem:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k... 阅读全文
posted @ 2015-12-03 19:50 爪哇国臣民 阅读(157) 评论(0) 推荐(0)
摘要:问题: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 ... 阅读全文
posted @ 2015-12-02 22:45 爪哇国臣民 阅读(104) 评论(0) 推荐(0)
摘要:1 public class Solution { 2 public ListNode mergeTwoLists(ListNode l1, ListNode l2) { 3 ListNode dummy1 = new ListNode(0), dummy2 = new L... 阅读全文
posted @ 2015-11-30 17:37 爪哇国臣民 阅读(143) 评论(0) 推荐(0)
摘要:问题:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique lon... 阅读全文
posted @ 2015-11-27 14:23 爪哇国臣民 阅读(149) 评论(0) 推荐(0)
摘要:问题:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telep... 阅读全文
posted @ 2015-11-27 14:15 爪哇国臣民 阅读(178) 评论(0) 推荐(0)
摘要:问题:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in th... 阅读全文
posted @ 2015-11-27 14:04 爪哇国臣民 阅读(166) 评论(0) 推荐(0)