![](https://img-blog.csdnimg.cn/4cbe946c6b67488891ef71a1e3da8372.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode
摘自leetcode题库
Take^that
可控的事情要谨慎,不可控的事情要乐观。
展开
-
LeetCode 20. Valid Parentheses有效的括号
1.Question: Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.2.Solution:public class Solution { public boolean isValid(Stri...原创 2019-08-03 08:41:41 · 90 阅读 · 0 评论 -
LeetCode 938. Range Sum of BST 求二叉搜索树的区间和
一、题目Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive).The binary search tree is guaranteed to have unique values.二、代码/** *...转载 2019-08-06 10:10:09 · 132 阅读 · 0 评论 -
LeetCode 543. Diameter of Binary Tree求二叉树的直径 java实现
一、题目Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or ...转载 2019-08-06 09:56:04 · 101 阅读 · 0 评论 -
LeetCode 700. Search in a Binary Search Tree
一、题目Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node’s value equals the given value. Return the subtree rooted with that node. If such...转载 2019-08-06 09:33:19 · 92 阅读 · 0 评论 -
LeetCode 450. Delete Node in a BST删除二叉搜索树的一个节点
一、题目Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.Basically, the deletion can be divided...转载 2019-08-06 09:29:03 · 109 阅读 · 0 评论 -
LeetCode 701. Insert into a Binary Search Tree二叉搜索树中插入新的结点 非递归与递归java实现
一、题目Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed th...转载 2019-08-05 11:06:13 · 111 阅读 · 0 评论 -
LeetCode 92. Reverse Linked List II 反转从位置 m 到 n 的链表。请使用一趟扫描完成反转
一、题目反转从位置 m 到 n 的链表。请使用一趟扫描完成反转。说明:1 ≤ m ≤ n ≤ 链表长度。示例:输入: 1->2->3->4->5->NULL, m = 2, n = 4输出: 1->4->3->2->5->NULL二、题解方法一: 递归使用递归反转链表的思路来源于反转字符串时使用的类似方法。反转字符串的一...转载 2019-08-05 10:48:54 · 306 阅读 · 0 评论 -
剑指offer_10 删除链表中重复的结点
一、题目描述Remove all elements from a linked list of integers that have value val.Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5二、题解递归public ListNode...转载 2019-07-16 14:18:35 · 102 阅读 · 0 评论 -
LeetCode 141. Linked List Cycle链表环
一、题目Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tai...转载 2019-08-04 14:54:24 · 105 阅读 · 0 评论 -
LeetCode 24. Swap Nodes in Pairs
一、题目Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list’s nodes, only nodes itself may be changed.二、递归演示三、代码递归实现:/** * Definition ...转载 2019-08-04 13:52:45 · 82 阅读 · 0 评论 -
LeetCode 19. Remove Nth Node From End of List从列表末尾删除第n个节点
一、题目Given a linked list, remove the n-th node from the end of list and return its head.二、代码实现/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode ne...转载 2019-08-04 09:58:17 · 85 阅读 · 0 评论 -
LeetCode 2. 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 contain a single digit. Add the two numbers and ret...转载 2019-08-04 09:38:09 · 88 阅读 · 0 评论 -
LeetCode 876. Middle of the Linked List返回链表的中间结点
一、题目Given a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.二、代码实现/** * Definition for singly-...转载 2019-08-04 08:27:48 · 104 阅读 · 0 评论 -
LeetCode 933. Number of Recent Calls求最近通话次数
一、题目Write a class RecentCounter to count recent requests.It has only one method: ping(int t), where t represents some time in milliseconds.Return the number of pings that have been made from 3000 m...转载 2019-08-04 08:04:36 · 126 阅读 · 0 评论 -
LeetCode 844. Backspace String Compare比较含退格的字符串
一、题目Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.二、大致思路对于第一个String S,遍历S里面的每个字符,如果当前字符不是‘#’,就存到栈sStack里面,如果当前字符是‘...转载 2019-08-03 16:37:30 · 129 阅读 · 0 评论 -
LeetCode 94. Binary Tree Inorder Traversal二叉树中序遍历 非递归
一、题目Given a binary tree, return the inorder traversal of its nodes’ values.Example:==⇒ D B E A C F二、简单演示整个流程的一小部分 如图:三、代码实现/** * Definition for a binary tree node. * public class...转载 2019-08-03 15:30:01 · 100 阅读 · 0 评论 -
LeetCode 145. Binary Tree Postorder Traversal二叉树后序遍历 非递归
一、题目Given a binary tree, return the preorder traversal of its nodes’ values.===> D E B F C A二、代码实现/** * Definition for a binary tree node. * public class TreeNode { * int val; * ...转载 2019-08-03 14:03:51 · 118 阅读 · 0 评论 -
LeetCode 144. Binary Tree Preorder Traversal二叉树前序遍历 非递归
一、题目Given a binary tree, return the preorder traversal of its nodes’ values.AB CD E====> A B D E C二、代码实现/** * Definition for a binary tree node. * public class TreeNode { * ...转载 2019-08-03 09:47:10 · 105 阅读 · 0 评论 -
LeetCode 617. Merge Two Binary Trees合并二叉树
一、题目Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary ...转载 2019-08-06 10:19:39 · 91 阅读 · 0 评论