![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
BFS
Ypopstar
这个作者很懒,什么都没留下…
展开
-
LeetCode--103--二叉树的锯齿形层次遍历
题目描述:给定一个二叉树,返回其节点值的锯齿形层次遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。输入:[3,9,20,null,null,15,7]输出:[[3],[20,9],[15,7]]题意:题目描述题解:简单bfs队列中利用奇偶性判断一下是从前往后还是从后往前代码:/** * Definition for a binary tree node. * public class TreeNode { * int val;原创 2020-07-06 16:27:08 · 128 阅读 · 0 评论 -
LeetCode--102--二叉树的层序遍历
题目描述:给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。输入:3/ 9 20/ 15 7输出:[[3],[9,20],[15,7]]题意:题目描述题解:层序遍历,BFS每次在一个队列里面取,取完之后弹出然后放代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode原创 2020-06-21 21:46:44 · 87 阅读 · 0 评论 -
LeetCode--107--二叉树的层次遍历 II
题目描述:给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)输入:3/ 9 20/ 15 7输出:[[15,7],[9,20],[3]]题意:题目描述题解:层序遍历,BFS每次在一个队列里面取,取完之后弹出然后放代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * T原创 2020-06-21 21:45:00 · 119 阅读 · 0 评论 -
HDOJ--1495--非常可乐
题目描述:大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,...原创 2020-04-22 23:00:29 · 112 阅读 · 0 评论 -
POJ--3984--迷宫问题
题目描述:定义一个二维数组:int maze[5][5] = {0, 1, 0, 0, 0,0, 1, 0, 1, 0,0, 0, 0, 0, 0,0, 1, 1, 1, 0,0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。输入描述:一个5 × 5的二维数组...原创 2020-04-22 22:55:02 · 329 阅读 · 0 评论 -
POJ--1426--Find The Multiple
题目描述:Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and...原创 2020-04-22 22:53:15 · 233 阅读 · 0 评论 -
POJ--2251--Dungeon Master
题目描述:You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north,...原创 2020-04-22 22:51:20 · 118 阅读 · 0 评论 -
HDOJ--1072--Nightmare
题目描述:Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb explodes. The in...原创 2020-04-21 23:04:51 · 129 阅读 · 0 评论 -
HDOJ--2612--Find a way
题目描述:Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.Yifenfei’s home is at t...原创 2020-04-20 22:50:26 · 96 阅读 · 0 评论 -
POJ--3126--Prime Path
题目描述:The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.— It is a matter ...原创 2020-04-20 22:48:16 · 145 阅读 · 0 评论 -
POJ--2312--Battle City
题目描述:Many of us had played the game “Battle city” in our childhood, and some people (like me) even often play it on computer now.What we are discussing is a simple edition of this game. Given a map ...原创 2020-04-18 22:34:24 · 125 阅读 · 0 评论 -
ZOJ--1649--Rescue
题目描述:Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.Angel’s friends wa...原创 2020-04-18 22:32:54 · 129 阅读 · 0 评论 -
牛客--2019快手--求x到y的最少计算次数
题目描述:给定两个-100到100的整数x和y,对x只能进行加1,减1,乘2操作,问最少对x进行几次操作能得到y?例如:a=3,b=11: 可以通过322-1,3次操作得到11;a=5,b=8:可以通过(5-1)*2,2次操作得到8;输入描述:输入以英文逗号分隔的两个数字,数字均在32位整数范围内。输出描述:输出一个数字输入:3,11输出:3题意:题目描述题解:暴力...原创 2020-03-27 20:01:15 · 1108 阅读 · 0 评论 -
POJ--3278--Catch That Cow
题目描述:Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤...原创 2020-03-11 11:44:59 · 127 阅读 · 0 评论