LeetCode
微丶念
所谓的不感兴趣,仅仅只是自己没有做好而已。
展开
-
LeetCode(8):word-break
题目描述 Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s ="leetcode", dict...原创 2018-03-07 22:44:18 · 418 阅读 · 0 评论 -
LeetCode(10):single-number
题目描述 Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it with...原创 2018-03-13 10:44:18 · 200 阅读 · 0 评论 -
LeetCode(7):linked-list-cycle-ii
题目描述 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve this without using extra space?思考 在《LeetCode(6):linked-l...原创 2018-03-05 10:29:30 · 219 阅读 · 0 评论 -
LeetCode(6):linked-list-cycle
题目描述 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?思考 看到这道题的第一眼其实是有点懵的,怎么样知道一个链表是否有环呢?显然我们不能简单地用某个指针q遍历链表,然后看是不是有q->...原创 2018-03-05 01:22:07 · 192 阅读 · 0 评论 -
LeetCode(5):reorder-list
题目描述 Given a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You must do this in-place without altering the nodes' values. For example, Given...原创 2018-03-04 20:45:29 · 218 阅读 · 0 评论 -
LeetCode(4):binary-tree-preorder-traversal
题目描述 Given a binary tree, return the preorder traversal of its nodes' values.思考 昨天在《binary-tree-preorder-traversal》中我们讲到了二叉树的后根序遍历,其中我们聊了如何使用递归方法和非递归方法解题,这里的前根序遍历也有这两种解法。 递归:/** * Def...原创 2018-03-04 13:43:15 · 143 阅读 · 0 评论 -
LeetCode(3):binary-tree-postorder-traversal
题目描述 Given a binary tree, return the postorder traversal of its nodes' values.思考 本题考查的是对于后序遍历的理解。后序遍历,全称叫做“后根序遍历”,即先遍历左子树,再遍历右子树,最后遍历根节点的遍历方式。对于二叉树的遍历,很容易想到的解决方法是递归,当然,我们也可以考考自己,尝试着用迭代的方法实...原创 2018-03-03 11:14:13 · 550 阅读 · 0 评论 -
LeetCode(9):copy-list-with-random-pointer
题目描述 A 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.思考 本题在传统链表节点的结构体...原创 2018-03-11 13:03:20 · 194 阅读 · 0 评论 -
LeetCode(2):insertion-sort-list
题目描述 Sort a linked list using insertion sort.思考 与《LeetCode(1):sort-list》一样,本题仍然采用链表作为存储结构,不过本题要求使用插入排序。关于插入排序的介绍可以参考十大经典排序算法、数据结构常见的八大排序算法、八大经典排序算法。 首先通过数组来看插入算法。 插入算法,顾名思义,将元素一个一...原创 2018-03-02 09:34:19 · 210 阅读 · 0 评论 -
LeetCode(12):longest-consecutive-sequence
题目描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The...原创 2018-03-15 21:59:08 · 277 阅读 · 0 评论 -
LeetCode(1):sort-list
题目描述 Sort a linked list in O(n log n) time using constant space complexity.思考 本题主要考查排序算法,我们需要对排序算法的时间复杂度以及空间复杂度有比较深刻的理解才能做好本题。推荐阅读:十大经典排序算法、数据结构常见的八大排序算法、八大经典排序算法。 各排序算法总结如下: ...原创 2018-03-01 10:17:44 · 275 阅读 · 0 评论 -
LeetCode(11):single-number-ii
题目描述 Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement i...原创 2018-03-13 17:34:32 · 199 阅读 · 0 评论