自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(54)
  • 收藏
  • 关注

原创 赵二的刷题日记053《合并两个有序链表》

Merge Two Sorted Lists Merge two sorted linked lists and return it as asortedlist. The list should be made by splicing together the nodes of the first two lists. Example 1: Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: ..

2021-08-01 09:17:53 102

原创 赵二的刷题日记052《爬台阶》

Climbing Stairs You are climbing a staircase. It takesnsteps to reach the top. Each time you can either climb1or2steps. In how many distinct ways can you climb to the top? Example 1: Input: n = 2 Output: 2 Explanation: There are two ways to ...

2021-07-30 08:42:11 108

原创 赵二的刷题日记051《二叉树中的搜索》

Search in a Binary Search Tree You are given therootof a binary search tree (BST) and an integerval. Find the node in the BST that the node's value equalsvaland return the subtree rooted with that node. If such a node does not exist, returnnull. ...

2021-07-28 08:52:24 113

原创 赵二的刷题日记050《反转链表》

Reverse Linked List Given theheadof a singly linked list, reverse the list, and returnthe reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [...

2021-07-28 08:51:06 102

原创 赵二的刷题日记049《两两交换链表节点》

Swap Nodes in Pairs Given alinked list, swap every two adjacent nodes and return its head. You must solve the problem withoutmodifying the values in the list's nodes (i.e., only nodes themselves may be changed.) Example 1: Input: head = [1,2,3,..

2021-07-27 08:28:26 44

原创 赵二的刷题日记048《字符串反转》

Reverse String Write a function that reverses a string. The input string is given as an array of characterss. Example 1: Input: s = ["h","e","l","l","o"] Output: ["o","l","l","e","h"] Example 2: Input: s = ["H","a","n","n","a","h"] Output: ["h.

2021-07-27 08:25:25 50

原创 赵二的刷题日记047《DFS模板》

递归实现: /* * Return true if there is a path from cur to target. */ boolean DFS(Node cur, Node target, Set<Node> visited) { return true if cur is target; for (next : each neighbor of cur) { if (next is not in visited) { a

2021-07-26 08:10:55 59

原创 赵二的刷题日记046《钥匙和房间》

Keys and Rooms There arenrooms labeled from0ton - 1and you start in the room0. All the rooms labeled from1tonare initially locked and you cannot enter a locked room without having its key. When you visit a room, you may find a set ofdistinc...

2021-07-26 08:07:58 76

原创 赵二的刷题日记045《01矩阵》

01 Matrix Given anm x nbinary matrixmat, returnthe distance of the nearest0for each cell. The distance between two adjacent cells is1. Example 1: Input: mat = [[0,0,0],[0,1,0],[0,0,0]] Output: [[0,0,0],[0,1,0],[0,0,0]] Example 2: In...

2021-07-24 08:30:55 89

原创 赵二的刷题日记043《BFS模板》

广度优先搜索使用队列,把还没访问过的结点依次放进队列,再拿出队头结点作为当前的遍历节点 模板如下: //1. 当不需要记录当前遍历到第几层时 while queue 不空: cur = queue.pop() for 节点 in cur的所有相邻节点: if 该节点有效且未访问过: queue.push(该节点) //2. 加入了level用于记录层数 level = 0 while queue 不空: size = queue.siz...

2021-07-23 09:00:15 75

原创 赵二的刷题日记044《洪水填充》

An image is represented by anm x ninteger gridimagewhereimage[i][j]represents the pixel value of the image. You are also given three integerssr,sc, andnewColor. You should perform aflood fillon the image starting from the pixelimage[sr][sc]. ...

2021-07-23 08:13:30 170

原创 赵二的刷题日记042《用栈实现队列》

Implement Queue using Stacks Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push,peek,pop, andempty). Implement theMyQueueclass: void push(int x)Pushes...

2021-07-22 08:07:25 105

原创 赵二的刷题日记041《字符串解码》

Decode String Given an encoded string, return its decoded string. The encoding rule is:k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. Note thatkis guaranteed to be a positive integer. You m...

2021-07-22 08:05:37 57

原创 赵二的刷题日记040《中序遍历二叉树栈实现》

Binary Tree Inorder Traversal Given therootof a binary tree, returnthe inorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [1,3,2] Example 2: Input: root = [] Output: [] Example 3: Input: root = [1] Ou...

2021-07-21 08:21:52 49

原创 赵二的刷题日记039《目标和》

Target Sum You are given an integer arraynumsand an integertarget. You want to build anexpressionout of nums by adding one of the symbols'+'and'-'before each integer in nums and then concatenate all the integers. For example, ifnums = [2, 1]...

2021-07-21 08:14:15 62

原创 赵二的刷题日记038《克隆图》

Clone Graph Given a reference of a node in aconnectedundirected graph. Return adeep copy(clone) of the graph. Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors. class Node { public int val; public Lis...

2021-07-20 08:12:45 54

原创 赵二的刷题日记037《岛屿数量》

Number of Islands Given anm x n2D binary gridgridwhich represents a map of'1's (land) and'0's (water), returnthe number of islands. Anislandis surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may a...

2021-07-20 08:10:57 110

原创 赵二的刷题日记036《逆波兰表达式》

Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression inReverse Polish Notation. Valid operators are+,-,*, and/. Each operand may be an integer or another expression. Notethat division between two integers should trunca...

2021-07-20 08:09:07 66

原创 赵二的刷题日记035《每日温度》

Daily Temperatures Given an array of integerstemperaturesrepresents the daily temperatures, returnan arrayanswersuch thatanswer[i]is the number of days you have to wait after theithday to get a warmer temperature. If there is no future day for ...

2021-07-19 08:29:36 75

原创 赵二的刷题日记034《有效的括号》

Valid Parentheses Given a stringscontaining just the characters'(',')','{','}','['and']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be c...

2021-07-19 08:28:46 57

原创 赵二的刷题日记033《最小栈》

Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement theMinStackclass: MinStack()initializes the stack object. void push(val)pushes the elementvalonto the stack. void pop()remov...

2021-07-19 08:27:37 40

原创 赵二的刷题日记032《打开转盘锁》

Open the Lock You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots:'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn'9'to be'0', or'0'to be'9'. Each ...

2021-07-18 08:06:40 48

原创 赵二的刷题日记031《岛屿数量》

Number of Islands Given anm x n2D binary gridgridwhich represents a map of'1's (land) and'0's (water), returnthe number of islands. Anislandis surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may a...

2021-07-17 09:24:30 109

原创 赵二的刷题日记030《最小公共父节点》

Lowest Common Ancestor of a Binary Tree Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodespandqas the ...

2021-07-16 08:37:37 45

原创 赵二的刷题日记029《设计循环队列》

Design Circular Queue Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the fir..

2021-07-16 08:34:45 71

原创 赵二的刷题日记028《填充每个节点的下一个右侧结点指针 II》

Populating Next Right Pointers in Each Node II Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer sho

2021-07-15 07:39:59 62

原创 赵二的刷题日记027《填充每个节点的下一个右侧节点指针》

Populating Next Right Pointers in Each Node You are given aperfect binary treewhereall leaves are on the same level, and every parent has two children. The binary tree has the following definition: struct Node { int val; Node *left; Node *r...

2021-07-15 07:34:37 71

原创 赵二的刷题日记026《从前序与中序遍历构造二叉树》

Construct Binary Tree from Preorder and Inorder Traversal Given two integer arrayspreorderandinorderwherepreorderis the preorder traversal of a binary tree andinorderis the inorder traversal of the same tree, construct and returnthe binary tr...

2021-07-13 16:28:13 56

原创 赵二的刷题日记025《从后序与中序遍历构造二叉树》

Construct Binary Tree from Inorder and Postorder Traversal Given two integer arraysinorderandpostorderwhereinorderis the inorder traversal of a binary tree andpostorderis the postorder traversal of the same tree, construct and returnthe binary ...

2021-07-13 16:26:11 50

原创 赵二的刷题日记024《路径总和》

Path Sum Given therootof a binary tree and an integertargetSum, returntrueif the tree has aroot-to-leafpath such that adding up all the values along the path equalstargetSum. Aleafis a node with no children. Example 1: Input: root = [5...

2021-07-12 11:15:06 60

原创 赵二的刷题日记023《对称链表》

Symmetric Tree Given therootof a binary tree,check whether it is a mirror of itself(i.e., symmetric around its center). Example 1: Input: root = [1,2,2,3,4,4,3] Output: true Example 2: Input: root = [1,2,2,null,3,null,3] Output: false ...

2021-07-11 21:56:36 44

原创 赵二的刷题日记022《二叉树的最大深度》

Maximum Depth of Binary Tree Given therootof a binary tree, returnits maximum depth. A binary tree'smaximum depthis the number of nodes along the longest path from the root node down to the farthest leaf node. Example 1: Input: root = [3,9,...

2021-07-11 21:54:32 67

原创 赵二的刷题日记021《层序遍历二叉树》

Binary Tree Level Order Traversal Given therootof a binary tree, returnthe level order traversal of its nodes' values. (i.e., from left to right, level by level). Example 1: Input: root = [3,9,20,null,null,15,7] Output: [[3],[9,20],[15,7]] E...

2021-07-11 11:19:45 76

原创 赵二的刷题日记《020》前、中、后序遍历二叉树

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { .

2021-07-11 10:49:48 54

原创 赵二的刷题日记019《反转k位链表》

Rotate List Given theheadof a linkedlist, rotate the list to the right bykplaces. Example 1: Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] Example 2: Input: head = [0,1,2], k = 4 Output: [2,0,1] /** * Definition for singly...

2021-07-10 19:25:51 64

原创 赵二的刷题日记018《两数相加II》

Add Two Numbers You are given twonon-emptylinked lists representing two non-negative integers. The digits are stored inreverse order, and each of their nodes contains a single digit. Add the two numbers and return the sumas a linked list. You may a...

2021-07-08 21:11:41 45

原创 赵二的刷题日记017《合并两个有序链表》

Merge Two Sorted Lists Merge two sorted linked lists and return it as asortedlist. The list should be made by splicing together the nodes of the first two lists. Example 1: Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: ..

2021-07-08 19:46:24 65

原创 赵二的刷题日记016《回文链表》

Palindrome Linked List Given theheadof a singly linked list, returntrueif it is a palindrome. Example 1: Input: head = [1,2,2,1] Output: true Example 2: Input: head = [1,2] Output: false /** * Definition for singly-linked list. * ...

2021-07-08 18:43:33 66

原创 赵二的刷题日记《反转链表》

Reverse Linked List Given theheadof a singly linked list, reverse the list, and returnthe reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] ...

2021-07-07 10:12:47 50

原创 赵二的刷题日记014《移除链表元素》

Remove Linked List Elements Given theheadof a linked list and an integerval, remove all the nodes of the linked list that hasNode.val == val, and returnthe new head. Example 1: Input: head = [1,2,6,3,4,5,6], val = 6 Output: [1,2,3,4,5] Examp...

2021-07-07 10:10:08 60

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除