自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 12.22(18)

【代码】12.22(18)

2024-12-27 16:30:38 207

原创 队列(线性表3)

1,一开始没有想到用一个数组来保存内存中是否已经有这个单词,我还在想能不能把Queue中的每一个元素都遍历出来,先获取front,再pop,然后又push到Queue中,然后发现这样没办法判断是否已经存在某个元素了,很可能重复存入某个元素。看完大佬代码才突然悟了。可能这就是菜鸟和大佬的区别吧。2,bool inq[1010]要设置为全局数组,因为全局数组会默认设置成false,局部变量就不行。整体思路其实就是模拟,但是我一开始没看明白题目要我干嘛,看完大佬代码后才了解。

2024-12-19 10:52:28 225

原创 栈(线性表2)

害,题目看好几遍没理解,一看大佬题解就会了。

2024-12-18 15:52:51 192

原创 2014.12.15(14/42)

我一开始一直在想怎么排序,然后使用了选择排序,于是超时了。后面发现,原来直接每个下标就是对应排序后的元素,是我观察不够仔细。

2024-12-16 16:42:34 281

原创 数组(线性表1)

用map数组查询更加方便。

2024-12-12 13:16:52 161

原创 函数与结构体(入门6)

主要是模拟,然后递归遍历右上角,左下角,右下角;此外,数组a设置成了int类型的话,然后memset(a,1,sizeof(a)),不知道为什么在输出的时候出现了乱码,我现在还无法解释;后面把它设置成了bool类型,memset(a,true,sizeof(a))就没问题。这里我借鉴的别人代码,由于本人对指针实在是不太了解,所以没有用大佬方法的指针,不过发现不用指针也可以做;在递归的时候,sum*=x应该写在判断x是否等于n之前,感觉是我递归不熟练,导致了错误。,推导过程大家可以自己去网上查找。

2024-12-12 10:11:58 619

原创 12.8(12)

服了我自己,我忘记在排序后vec1的原始的下标变了,我还一直用排序后的下标在比较,浪费一堆时间。

2024-12-11 15:20:40 248

原创 字符串(入门5)

去除多余的0,不仅可以在翻转之后去除,也可以在翻转以前去除,我之前一直想怎么在反转了以后再去除,就有点麻烦,而且自己也绕晕了,后面参考大佬的代码后才明白,囧。2,第二次for循环的时候,只判断s[i]==s[i-1]的时候就可以了,不用分开判断s[i+1]=='V'和=='K'的时候。还有一个点我要改的是:习惯性在输出后面加上endl换行,导致我有一部分的测试数据过不了,发现是我在输出符号之后直接换行了。1,第一次for循环找到VK后,需要把对应的s[i]改为X,避免后面循环的时候误算进去。

2024-12-05 11:46:37 232

原创 数组(入门4)

这道题的话,感觉也没什么含金量(bushi),就是把依据输入的数字,一行一行的添加到String ans[10](注意不是ans[5]这样的结果是错误的,因为我是从下标为1开始的,其实也可以设置为ans[6])中。像这种,有重合部分,而且如果分情况讨论的话,比较复杂多样,比如说这道题,需要判断第二次输入的u2是不是比上一个v1要小,是否相等,又或者比它大;1,那个minn=3e5+1,不是3e3+1,我一开始直接按照m,n的最大值来设置的,结果ai<=100,还要再乘100,泪目;

2024-12-02 20:23:18 909

原创 11.24(46)

(4)OK数组是标记的可达路径,一开始就在DFS中把ok[x][y]=true,是因为main里面调用第一遍函数的时候,传入的是(2,2),这个点一定是冰,而后面调用之前,都会判断过不是‘#’之后才标记为true。并在循环输入s[i]后,加上一句,s[i]='#'+s[i],顺序不能调换,因为题目说了,周围边界都是障碍物,这里就是把每行的最左边都设置为障碍物,防止数组的越界行为。(2)循环遍历(深度优先搜索)一个方向,不是障碍物,就一直遍历,直到遇见障碍物,同时更新x,y的值。

2024-11-27 16:03:49 775

原创 循环结构(入门3)

/ 全局变量// 全局变量这两个数组是全局变量,存储在数据段(data segment)中,而不是栈上。数据段通常用于存储全局变量、静态变量以及常量等。它不受栈大小限制,因此可以存储较大的数组。// 局部变量// 局部变量...这些数组是局部变量,默认分配在栈上。如果你定义一个过大的数组,栈空间可能不足以容纳它,尤其是在数组大小很大的时候(例如和栈的大小限制因编译器、操作系统等因素而异,通常情况下,栈空间的限制要小于堆空间,因此当你在main。

2024-11-21 11:00:09 635

原创 11.17训练(25)

高桥正在开发一个RPG游戏。他决定编写一段代码来检查两个地图是否相等。我们有一个 AA 和一个 BB,它们分别有 HH 行和 WW 列。每个单元格上都写着符号或。在 AA 和 BB 中,位于从上往下数第 ii 行和从左往右数第 jj 列的单元格上的符号分别用 Ai,jAi,j​ 和 Bi,jBi,j​ 表示。以下两种操作分别称为和。是否存在一对非负整数 (s,t)(s,t) 满足以下条件?如果存在,则打印Yes,否则打印No。

2024-11-18 17:56:58 593

原创 分支结构(洛谷——入门顺序2)

题目给出的识别码可能已经是X了,这时候直接比较s的最后一位是否和它相同就好,而不是只比较数字的时候。1,被除数有可能是0(即t==0的时候),需要额外考虑。2,有可能在限定时间内已经吃完了,这时候就应该输出0。

2024-11-16 19:47:19 246

原创 洛谷——顺序结构(入门)

其他的几道题目太简单了,没有写。

2024-11-14 10:00:48 176

原创 栈与队列章节总结(代码随想录)

好久不见啦,最近学业太繁忙,一周才断断续续地重新写完栈与队列章节题目和总结。

2024-11-13 16:35:48 256

原创 对二叉树章节的总结

我真累麻了,花了几个小时把目前做过的所有的二叉树题目做了一个总结。

2024-10-23 21:02:22 430

原创 538. Convert BST to Greater Tree

Given the of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.As a reminder, a binary search tree is a tree that s

2024-10-22 19:34:50 912

原创 108. Convert Sorted Array to Binary Search Tree

Given an integer array where the elements are sorted in ascending order, convert it to a height-balancedbinary search tree.Example 1:Input: nums = [-10,-3,0,5,9]Output: [0,-3,9,-10,null,5]Explanation: [0,-10,5,null,-3,null,9] is also accepted:Examp

2024-10-22 19:12:23 965

原创 669. Trim a Binary Search Tree

Given the of a binary search tree and the lowest and highest boundaries as and , trim the tree so that all its elements lies in . Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's de

2024-10-21 21:27:05 672

原创 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 into two stages:Example 1:Input: root = [5,3,6,2,4,null,7],

2024-10-21 16:52:36 784

原创 701. Insert into a Binary Search Tree

You are given the node of a binary search tree (BST) and a to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.Notice that there may exist multiple valid way

2024-10-21 15:37:18 705

原创 235. Lowest Common Ancestor of a Binary Search Tree

qpq。

2024-10-18 10:02:21 928

原创 236. Lowest Common Ancestor of a Binary Tree

qpq。

2024-10-17 20:30:26 647

原创 501. Find Mode in Binary Search Tree

Given the of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it.If the tree has more than one mode, return them in any order.Assume a BST is defined as follows:Example 1:Input: root = [1,

2024-10-17 11:02:10 875

原创 530. Minimum Absolute Difference in BST

Given the of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.Example 1:Input: root = [4,2,6,1,3]Output: 1Example 2:Input: root = [1,0,48,null,null,12,49]Output: 1Constr

2024-10-15 20:11:44 857

原创 98. Validate Binary Search Tree

Given the of a binary tree, determine if it is a valid binary search tree (BST).A valid BST is defined as follows:subtreeExample 1:Input: root = [2,1,3]Output: trueExample 2:Input: root = [5,1,4,null,null,3,6]Output: falseExplanation: The root nod

2024-10-14 16:31:29 814

原创 700. Search in a Binary Search Tree

You are given the of a binary search tree (BST) and an integer .Find the node in the BST that the node's value equals and return the subtree rooted with that node. If such a node does not exist, return .Example 1:Input: root = [4,2,7,1,3], val = 2Outpu

2024-10-14 15:37:35 455

原创 617. Merge Two Binary Trees

You are 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 the two trees into a new binary tree. The merge rule is that if two nodes

2024-10-14 15:01:51 730

原创 654. Maximum Binary Tree

1)先做,后做。

2024-10-13 20:31:19 885

原创 106. Construct Binary Tree from Inorder and Postorder Traversal

1)先做,后做主函数中判断两个数组是否为空,空---NULL;不空----traversal函数第一步,判断postorder数组是否为空(size=0)---NULL第二步,后序遍历到的最后一个元素作为root。

2024-10-12 15:47:31 932

原创 112. Path Sum

Given the of a binary tree and an integer , return if the tree has a root-to-leaf path such that adding up all the values along the path equals .A leaf is a node with no children.Example 1:Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetS

2024-10-08 17:25:07 1020

原创 513. Find Bottom Left Tree Value

Given the of a binary tree, return the leftmost value in the last row of the tree.Example 1:Input: root = [2,1,3]Output: 1Example 2:Input: root = [1,2,3,4,null,5,6,null,null,7]Output: 7Constraints:注意: 1,更新的时候是更新maxDepth=Depth,不要写反

2024-10-08 16:05:32 236

原创 404. Sum of Left Leaves

Given the of a binary tree, return the sum of all left leaves.A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.Example 1:Input: root = [3,9,20,null,null,15,7]Output: 24Explanation: There are two left leave

2024-09-29 10:50:43 451

原创 257. Binary Tree Paths

Given the of a binary tree, return all root-to-leaf paths in any order.A leaf is a node with no children.Example 1:Input: root = [1,2,3,null,5]Output: ["1->2->5","1->3"]Example 2:Input: root = [1]Output: ["1"]Constraints:思路:

2024-09-29 09:51:43 672

原创 110. Balanced Binary Tree

Given a binary tree, determine if it isheight-balanced.Example 1:Input: root = [3,9,20,null,null,15,7]Output: trueExample 2:Input: root = [1,2,2,3,3,null,null,4,4]Output: falseExample 3:Input: root = []Output: trueConstraints:思路:

2024-09-28 12:03:40 329

原创 完全二叉树的节点个数

Given the of a complete binary tree, return the number of the nodes in the tree.According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It

2024-09-28 11:17:19 636

原创 二叉树最小深度

25[0, 105]

2024-09-27 11:50:10 517

原创 最大深度(二叉树+N叉树)

Given the of a binary tree, return its maximum depth.A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Example 1:Input: root = [3,9,20,null,null,15,7]Output: 3Example 2:Inpu

2024-09-26 10:50:27 639

原创 对称二叉树

Given the of 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: trueExample 2:Input: root = [1,2,2,null,3,null,3]Output: falseConstraints:Follow up: Could you

2024-09-25 21:21:40 410

原创 1009 Product of Polynomials

【代码】1009 Product of Polynomials。

2024-09-19 11:18:36 328

空空如也

空空如也

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

TA关注的人

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