打家劫舍leetcode 007 198

4月17日leetcode二叉树的层序遍历II

给你二叉树的根节点 root ,返回其节点值 自底向上的层序遍历 。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)(出自力扣) 这个昨天的二叉树的层序遍历有所不同:需要将从后往前层序遍历二叉树,其实很简单,只需要用vector的逆置函数,将vector中的vector逆置即可。 这里顺 ......
leetcode

4月16日leetcode二叉树前序遍历创建字符串,二叉树的层序遍历

给你二叉树的根节点 root ,请你采用前序遍历的方式,将二叉树转化为一个由括号和整数组成的字符串,返回构造出的字符串。 空节点使用一对空括号对 "()" 表示,转化后需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。 来源:力扣(LeetCode)链接:https://leetc ......
字符串 字符 leetcode

LeetCode Top100: 对称二叉树 (Python)

给你一个二叉树的根节点 root , 检查它是否轴对称。 示例 1: 输入:root = [1,2,2,3,4,4,3] 输出:true 示例 2: 输入:root = [1,2,2,null,3,null,3] 输出:false 提示: 树中节点数目在范围 [1, 1000] 内 -100 <= ......
LeetCode Python 100 Top

LeetCode Top100:二叉树的中序遍历(Python)

给定一个二叉树的根节点 root ,返回 它的 中序 遍历 。 示例 1: 输入:root = [1,null,2,3] 输出:[1,3,2] 示例 2: 输入:root = [] 输出:[] 示例 3: 输入:root = [1] 输出:[1] 提示: 树中节点数目在范围 [0, 100] 内 - ......
LeetCode Python 100 Top

2-211-(LeetCode-470) 用 Rand7() 实现 Rand10()

1. 题目 https://leetcode.cn/problems/implement-rand10-using-rand7/submissions/425373186/ 2. 解法 class Solution extends SolBase { public int rand10() { in ......
Rand LeetCode Rand7 211 470

2-209-(LeetCode-121) 买卖股票的最佳时机

1. 题目 https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/ 121. 买卖股票的最佳时机 2. 解法 2.1 解法一:动态规划 2.2 解法二:非动态规划 if (prices.length < 2) { return 0; ......
时机 LeetCode 股票 209 121

代码随想录 46天 day198.打家劫舍 | | 337.打家劫舍 III | 213.打家劫舍II

你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。 给定一个代表每个房屋存放金额的非负整数数组,计算你 不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额。 示例 ......
打家劫舍 随想录 随想 代码 day

「解题报告」AGC007E Shik and Travel

不难的题,但是突然就不会分析复杂度了!脑子出了些什么问题。 首先考虑题目中要求一条边恰好经过两次,那么也就是说每进入一个子树,那么就必须把子树内的所有点探索完后再去另一个子树,那么这个问题就显然是可以递归处理的了。 具体来说,对于每一个子树 $u$,都存在若条路径 $u \to v$,然后当子树合并 ......
报告 Travel 007E Shik AGC

2-207-通过(LeetCode-509)熟悉动态规划的解题步骤

1. 题目 运态规划的定义 动态规划的解题步骤 2. 解法 2.1 递归 public static int fibonacci(int n) { if (n == 0) { return 0; } if (n == 1) { return 1; } return fibonacci(n - 1) ......
LeetCode 步骤 动态 207 509

团体天梯练习 L2-007 家庭房产

#L2-007 家庭房产 给定每个人的家庭成员和其自己名下的房产,请你统计出每个家庭的人口数、人均房产面积及房产套数。 ####输入格式: 输入第一行给出一个正整数 $ N(≤1000)$,随后N行,每行按下列格式给出一个人的房产: 编号 父 母 $k$ 孩子1 ... 孩子 $k$ 房产套数 总面 ......
天梯 团体 家庭 房产 007

LeetCode Top100: 爬楼梯 (python)

假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 示例 1: 输入:n = 2 输出:2 解释:有两种方法可以爬到楼顶。 1. 1 阶 + 1 阶 2. 2 阶 示例 2: 输入:n = 3 输出:3 解释:有三种方法可以爬到楼顶 ......
楼梯 LeetCode python 100 Top

LeetCode Top100: 合并两个有序链表 (python)

将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 1: 输入:l1 = [1,2,4], l2 = [1,3,4] 输出:[1,1,2,3,4,4] 示例 2: 输入:l1 = [], l2 = [] 输出:[] 示例 3: 输入:l1 = [] ......
LeetCode 两个 python 100 Top

leetcode160-相交链表

leetcode160 方法一:哈希表 思路: 先创建一个unordered_set,存放ListNode*类型的变量 先遍历其中一个链表,把所有节点的指针放在set中 再遍历另一个链表,查找是否存在一个节点已经在set中,如果存在则说明这是它们的相交节点的指针,返回这个指针,如果不存在则说明不存在 ......
leetcode 160

LeetCode-Top100: 有效的括号 (python)

给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。 每个右括号都有一个对应的相同类型的左括号。 示例 1: 输入:s = "()" 输出:true 示例 2: 输入 ......
括号 LeetCode-Top LeetCode python 100

leetcode_打卡5

leetcode_打卡5 题目:345. 反转字符串中的元音字母 思路:双指针 class Solution { public String reverseVowels(String s) { int n=s.length(); char[] arr=s.toCharArray(); int i=0 ......
leetcode

LeetCode-Top100:两数之和(python)

给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。 示例 1: 输入:nums = [2,7, ......
之和 LeetCode-Top LeetCode python 100

LeetCode 双周赛 102,模拟 / BFS / Dijkstra / Floyd

本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 提问。 大家好,欢迎来到小彭的 LeetCode 周赛解题报告。 昨晚是 LeetCode 双周赛第 102 场,你参加了吗?这场比赛比较简单,拼的是板子手速,继上周掉大分后算是回了一口血 😁。 2618. 查询网 ......
LeetCode Dijkstra Floyd 102 BFS

【前缀和】LeetCode 523. 连续的子数组和

题目链接 523. 连续的子数组和 思路 参考宫水三叶大佬题解 一开始以为和 Leetcode 53 Maximum Subarray 思路差不多,都是求子数组的值。但是后来发现在53题中并没有求出每个子数组的和,只是在贪心的情况下求出了可能的最大和 代码 class Solution { publ ......
前缀 数组 LeetCode 523

[LeetCode] 1042. Flower Planting With No Adjacent

You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. I ......
LeetCode Adjacent Planting Flower 1042

LeetCode 115. 不同的子序列

class Solution { public: long long f[1010][1010];//f[i][j]表示s前i个字符得到t前j个字符的所有方案 int numDistinct(string s, string t) { f[0][0]=1; int n=s.size(),m=t.si ......
序列 LeetCode 115

LeetCode/最大化城市的最小供电站数目

政府批准了可以额外建造 k 座供电站,你需要决定这些供电站分别应该建在哪里,这些供电站与已经存在的供电站有相同的供电范围。 给你两个整数 r 和 k ,如果以最优策略建造额外的发电站,返回所有城市中,最小供电站数目的最大值是多少。 ###一. 二分法+前缀和+贪心 分析:最大化最小值,首先考虑使用二 ......
供电站 数目 LeetCode 城市

leetcode-1337-easy

The K Weakest Rows in a Matrix You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers ......
leetcode 1337 easy

leetcode-1342-easy

Number of Steps to Reduce a Number to Zero Given an integer num, return the number of steps to reduce it to zero. In one step, if the current number i ......
leetcode 1342 easy

leetcode-1360-easy

Number of Days Between Two Dates Write a program to count the number of days between two dates. The two dates are given as strings, their format is YY ......
leetcode 1360 easy

leetcode-766-easy

Toeplitz Matrix Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false. A matrix is Toeplitz if every diagonal from top ......
leetcode easy 766

leetcode-806-easy

Number of Lines To Write String You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase ......
leetcode easy 806

leetcode-812-easy

Largest Triangle Area Given an array of points on the X-Y plane points where points[i] = [xi, yi], return the area of the largest triangle that can be ......
leetcode easy 812

leetcode-830-easy

Positions of Large Groups In a string s of lowercase letters, these letters form consecutive groups of the same character. For example, a string like ......
leetcode easy 830

leetcode-844-easy

Backspace String Compare Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace c ......
leetcode easy 844

leetcode-944-easy

Delete Columns To Make Sorted You are given an array of n strings strs, all of the same length. The strings can be arranged such that there is one on ......
leetcode easy 944