LeetCode
文章平均质量分 59
Fan2g
这个作者很懒,什么都没留下…
展开
-
LeetCode刷题-1——Two sum(两数之和)
链接:https://leetcode.com/problems/two-sum/description/题目:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input ...原创 2018-06-15 09:18:31 · 465 阅读 · 0 评论 -
LeetCode刷题-——Maximum Depth of Binary Tree(二叉树的最大深度)
链接:点击打开链接题目:给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。Example:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回它的最大深度 3 。解析:如果根节点为空,则深度为0,返回0,递归的出口如果根节点不为空,那么深度至少为1,然后我们求他们左右子树...原创 2018-06-18 20:44:22 · 378 阅读 · 0 评论 -
LeetCode刷题-141——Linked List Cycle(判断链表中是否有环)
链接:点击打开链接题目:Given a linked list, determine if it has a cycle in it.Notes:Can you solve it without using extra space?解析:由于每一个父亲只有可能有一个孩子,故这里的环实际上是指list中某一个节点的孩子同时也是它自己或者他的祖先。 这个问题需要注意几种情况:1. 空链表不成环2. 一...原创 2018-06-16 16:47:44 · 287 阅读 · 0 评论 -
LeetCode刷题-234——Palindrome Linked List(回文链表)
链接:点击打开链接题目:Given a singly linked list, determine if it is a palindrome.Example:Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueNotes:Could you do it in O(n) tim...原创 2018-06-16 15:49:48 · 208 阅读 · 0 评论 -
LeetCode刷题-206——Reverse Linked List(反转链表)
链接:https://leetcode.com/explore/interview/card/top-interview-questions-easy/93/linked-list/560/题目:Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5原创 2018-06-15 09:19:38 · 221 阅读 · 0 评论 -
LeetCode刷题-21——Merge Two Sorted Lists(合并连个有序链表)
链接:https://leetcode.com/problems/merge-two-sorted-lists/description/题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of th...原创 2018-06-15 09:19:23 · 232 阅读 · 0 评论 -
LeetCode刷题-19——Remove Nth Node From End of List( 删除链表的倒数第N个节点 )
链接:https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/题目:给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。Example:给定一个链表: 1->2->3->4->5, 和 n = 2.当删除了倒数第二个节点后,链表变为 1-&gt...原创 2018-06-15 09:18:58 · 215 阅读 · 0 评论 -
LeetCode刷题-28——Implement strStr()
链接:https://leetcode.com/problems/implement-strstr/description/题目:Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Ex...原创 2018-06-15 09:19:12 · 162 阅读 · 0 评论 -
LeetCode刷题-26—— Remove Duplicates from Sorted Array(删除排序数组中的重复项)
链接:https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/题目:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return t...原创 2018-06-15 09:18:44 · 326 阅读 · 0 评论 -
LeetCode刷题-7—— Reverse Integer(反转整数)
链接:https://leetcode.com/problems/reverse-integer/description/题目:Given a 32-bit signed integer, reverse digits of an integer.Example:Example 1:Input: 123Output: 321Example 2:Input:...原创 2018-06-15 09:18:18 · 204 阅读 · 0 评论 -
LeetCode刷题-98——Validate Binary Search Tree(验证搜索二叉树)
链接:点击打开链接题目:给定一个二叉树,判断其是否是一个有效的二叉搜索树。一个二叉搜索树具有如下特征:节点的左子树只包含小于当前节点的数。节点的右子树只包含大于当前节点的数。所有左子树和右子树自身必须也是二叉搜索树。Example:示例1输入: 2 / \ 1 3输出: true示例2 5 / \ 1 4 / \ 3 6Outpu...原创 2018-06-18 21:34:47 · 964 阅读 · 0 评论