Coding Rabbit


  • 首页

  • 关于

  • 归档

  • 标签

  • 搜索

Reorder List || Partition List

发表于 2017-02-08
Reorder ListQuestionGiven a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes’ values. For example, Given {1,2,3,4}, reorder it to {1,4,2,3}. Analysis 将一个链表以中点分为两段 l1,l2,并将 l2 reverse 遍历两个链表,将第二半链表中的点依次插入第一个链表中 注意在遍历插入节 ...
阅读全文 »

Copy List with Random Pointer || Clone Graph

发表于 2017-02-05
Copy List with Random PointerQuestionA linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. Analysis LeetCode DIscussion 将整个链表复制一遍,复制节点紧跟原节点 复制每个节点的random指针,复制节点的random指针同理指向复制节点 提取复制后的链表 复 ...
阅读全文 »

Jump Game || Gas Station

发表于 2017-02-04
Jump GameQuestionGiven an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. For example: A = [2,3,1,1,4], return true. A = [3 ...
阅读全文 »

Find All Duplicates in an Array || Find All Numbers Disappeared in an Array

发表于 2017-02-04
Find All Duplicates in an ArrayQuestionGiven an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? Example: 12345Input:[4,3,2,7,8,2,3,1 ...
阅读全文 »

Word Ladder Series

发表于 2017-02-02
Word LadderQuestionGiven two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that: Only one letter can be changed at a time. Each transformed word must exist in the word list. Note that beginWord is not ...
阅读全文 »

Sum of Two Integers

发表于 2017-02-01
Sum of Two IntegersQuestionCalculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. Analysis a&b 对于同一位,相同且均为1才会产生进位,故a&b可得进位carry a^b 相当于+操作,同为1产生进位当前位为0,同为0所得为0,不同数字才会得当前位为1的结果 由于进位只能向前进位,故每次对carry进行左移位赋给b,直至b= ...
阅读全文 »

Sort Characters By Frequency || Top K Frequent Elements

发表于 2017-01-29
Sort Characters By FrequencyQuestionGiven a string, sort it in decreasing order based on the frequency of characters. Example 1: 123456789**Input:**"tree"**Output:**"eert"**Explanation:**'e' appears twice while 'r' and 't' both appear once.So 'e' must appear before both 'r' and 't'. Therefore "eetr" ...
阅读全文 »

Spiral Matrix Series

发表于 2017-01-23
Spiral Matrix IQuestionGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: 12345[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]] You should return [1,2,3,6,9,8,7,4,5]. Analysis利用四个变量colbegin,colend,rowbegin,rowend来 ...
阅读全文 »

Interleaving String || Decode Ways

发表于 2017-01-23
Interleaving StringQuestionGiven s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 ="aadbbcbcac", return true. When s3 = "aadbbbaccc", return false. Analysis 中文题解 对于 s1 = a1, a2 ……. ...
阅读全文 »

Binary Tree Maximum Path Sum || Binary Tree Postorder Traversal

发表于 2017-01-22
Binary Tree Maximum Path SumQuestionGiven a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through ...
阅读全文 »
123…8
Coding Rabbit

Coding Rabbit

77 日志
37 标签
RSS
Github Facebook weibo
Links
  • Codeboy
  • Yijia_Jin
© 2017 Coding Rabbit
由 Hexo 强力驱动
主题 - NexT.Mist