leetcode
EightAflytek
这个作者很懒,什么都没留下…
展开
-
N皇后(Python)2021-07-29
LeetCode -------- 51.N皇后N 皇后n 皇后问题 研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。给你一个整数 n ,返回所有不同的 n 皇后问题 的解决方案。每一种解法包含一个不同的 n 皇后问题 的棋子放置方案,该方案中 ‘Q’ 和 ‘.’ 分别代表了皇后和空位。示例 1:输入:n = 4输出:[[".Q…","…Q",“Q…”,"…Q."],["…Q.",“Q…”,"…Q",".Q…"]]解释:如上图所示,4 皇后问题存在原创 2021-07-29 20:20:10 · 147 阅读 · 0 评论 -
c++ leetcode199
199. 二叉树的右视图给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。示例:输入: [1,2,3,null,5,null,4]输出: [1, 3, 4]解释: 1 <--- / \2 3 <--- \ \ 5 4 <---代码:/** * Definition for a binary tree node. * struct T原创 2021-06-21 17:47:52 · 104 阅读 · 0 评论 -
c++ leetcode107
107. 二叉树的层序遍历 II给定一个二叉树,返回其节点值自底向上的层序遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其自底向上的层序遍历为:[ [15,7], [9,20], [3]]代码:/** * Definition for a binary tree node. * struct Tree原创 2021-06-21 17:46:37 · 118 阅读 · 0 评论 -
c++ leetcode102
102. 二叉树的层序遍历给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。示例:二叉树:[3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其层序遍历结果:[ [3], [9,20], [15,7]]代码:/** * Definition for a binary tree node. * struct TreeNode { * int原创 2021-06-21 17:44:29 · 104 阅读 · 0 评论 -
c++ leetcode145
145. 二叉树的后序遍历给定一个二叉树,返回它的 后序 遍历。示例:输入: [1,null,2,3] 1 \ 2 / 3 输出: [3,2,1]进阶: 递归算法很简单,你可以通过迭代算法完成吗?代码一:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *righ原创 2021-06-21 17:41:42 · 92 阅读 · 0 评论 -
c++ leetcode94
94. 二叉树的中序遍历给定一个二叉树的根节点 root ,返回它的 中序 遍历。示例 1:输入:root = [1,null,2,3]输出:[1,3,2]示例 2:输入:root = []输出:[]示例 3:输入:root = [1]输出:[1]示例 4:输入:root = [1,2]输出:[2,1]示例 5:输入:root = [1,null,2]输出:[1,2]提示:树中节点数目在范围 [0, 100] 内-100 <= Node.val <原创 2021-06-21 17:39:26 · 79 阅读 · 0 评论 -
c++leetcode144
144. 二叉树的前序遍历给你二叉树的根节点 root ,返回它节点值的 前序 遍历。示例 1:输入:root = [1,null,2,3]输出:[1,2,3]示例 2:输入:root = []输出:[]示例 3:输入:root = [1]输出:[1]示例 4:输入:root = [1,2]输出:[1,2]示例 5:输入:root = [1,null,2]输出:[1,2]提示:树中节点数目在范围 [0, 100] 内-100 <= Node.val &l原创 2021-06-21 17:36:37 · 106 阅读 · 0 评论 -
Leetcode54(c++).
54. 螺旋矩阵给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/spiral-matrix著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。示例 1:输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]输出:[1,2,3,6,9,8,7,4,5]示例 2:输入:matrix = [[1,2原创 2021-05-25 21:53:32 · 65 阅读 · 0 评论 -
Leetcode59(c++).
Leetcode59(c++).Spiral Matrix IIGiven a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/spiral-matrix-ii著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。Example 1:原创 2021-05-24 21:51:41 · 94 阅读 · 0 评论 -
Leetcode93(c++).
Leetcode93(c++).Restore IP AddressesGiven a string s containing only digits, return all possible valid IP addresses that can be obtained from s. You can return them in any order.A valid IP address consists of exactly four integers, each integer is betwe原创 2021-05-23 22:44:28 · 157 阅读 · 0 评论 -
Leetcode34(c++).
leetcode34 (c++).Find First and Last Position of Element in Sorted ArrayGiven an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.If target is not found in the array, return [-1, -1].You mu原创 2021-05-20 20:11:50 · 184 阅读 · 0 评论 -
Leetcode209(c++).
leetcode: 209Minimum Size Subarray Sum.Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray [numsl, numsl+1, …, numsr-1, numsr] of which the sum is greater than or equal to target. If原创 2021-05-19 20:32:18 · 119 阅读 · 0 评论