字典leetcode tire 371
python字典的使用
通过名称来访问各个值得数据结构,这种数据结构称为字典。字典是Python中唯一得内置映射类型。 函数dict 可使用函数dict从其他映射(如其他字典)或键-值对序列创建字典。 >>> items=[('name','bob'),('age','26')] >>> d=dict(items) >>> ......
【LeetCode 2701. 连续递增交易】MySQL用户变量编程得到严格递增连续子序列的开始位置,结束位置,长度等统计信息
题目地址 https://leetcode.cn/problems/consecutive-transactions-with-increasing-amounts/ 代码 # Write your MySQL query statement below with t1 as( select * # ......
【Leetcode 2474. 购买量严格增加的客户】MySQL用户变量编程解决严格递增连续子序列问题
题目地址 https://leetcode.cn/problems/customers-with-strictly-increasing-purchases/description/ 代码 # Write your MySQL query statement below with t1 as( se ......
【LeetCode 2494. 合并在同一个大厅重叠的活动】MySQL用户变量编程解决区间合并问题
题目地址 https://leetcode.cn/problems/merge-overlapping-events-in-the-same-hall/ 代码 # Write your MySQL query statement below with t2 as( select * # 只需要改动这 ......
【LeetCode1747. 应该被禁止的 Leetflex 账户】MySQL用户变量编程;尝试维护一个multiset
题目地址 https://leetcode.cn/problems/leetflex-banned-accounts/description/ 代码 with t1 as( select account_id,ip_address, login as tick, "login" as mytype ......
【Leetcode1949. 坚定的友谊】使用MySQL在无向图中寻找{"CompleteTripartite", {1, 1, 3}}这个pattern
题目地址 https://leetcode.cn/problems/strong-friendship/ 思路 就是在无向图中寻找这个pattern: (* Mathematica *) GraphData[{"CompleteTripartite", {1, 1, 3}}] SQL写还是比较麻烦。 ......
【LeetCode 2142. 每辆车的乘客人数 I】乘客到站等车,车到站载客。MySQL用户变量编程完成
题目地址 https://leetcode.cn/problems/the-number-of-passengers-in-each-bus-i/description/ 思路 将所有关键时刻作为tick。(同一时刻车和人同时到,默认人在车前到) 之后按照tick升序,使用MySQL用户变量编程完成 ......
【LeetCode 】练习str_to_date函数;over(rows between CURRENT ROW AND 2 following)实现【当月和接下来2个月】滑动窗口
题目地址 https://leetcode.cn/problems/hopper-company-queries-iii/description/ 代码 -- CTE生成2020年每月的最后一天 WITH RECURSIVE months AS ( SELECT LAST_DAY('2019-12- ......
列表 元组 字典 转化
#列表转化为元组listxuhao =[102,105,109]listzhi =["张三","李四","王五"]toool = list(zip(listxuhao,listzhi))print(toool)# 元组转化为字典zidian ={x:y for x,y in toool}print( ......
leetcode 15.三数之和
leetcode 15.三数之和 第十五题:三数之和 1.排序 + 双指针: 和两数之和不同,但可以转化为类似的思路,即确定一个数,去找数组中是否有另外两个数之和等于它的相反数。本题的难点在于如何去除重复解,如果是无序数组,则需要对每个值所在的位置进行记录并进行比较。但如果是有序数组且相加结果为0, ......
[LeetCode] 2085. Count Common Words With One Occurrence
Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays. Example 1: Input: words1 = ......
【LeetCode 1635. Hopper 公司查询 I】with recursive生成2020年每月的最后一天
题目地址 https://leetcode.cn/problems/hopper-company-queries-i/description/ 代码 -- CTE生成2020年每月的最后一天 WITH RECURSIVE months AS ( SELECT LAST_DAY('2019-12-01 ......
【LeetCode 2854. 滚动平均步数】MySQL过去n日滑动窗口
题目地址 https://leetcode.cn/problems/rolling-average-steps/description/ 代码 WITH t1 AS ( SELECT user_id, steps_date, CASE WHEN COUNT(steps_count) OVER ( P ......
【LeetCode 2989. 班级表现】T-SQL 动态sql编程示例
题目地址 https://leetcode.cn/problems/class-performance/description/ 题目大意 编写一个查询,计算学生获得的 最高分 和 最低分 之间的 总分差(3 次作业的总和)。 代码 /* Write your T-SQL query stateme ......
【LeetCode 2994. 发生在周五的交易 II】with recursive生成2023-11月所有周五的日期
题目地址 https://leetcode.cn/problems/friday-purchases-ii/description/ 代码 # Write your MySQL query statement below WITH RECURSIVE Fridays (week_of_month, ......
【LeetCode2993. 发生在周五的交易 I】MySQL里尝试实现weekofmonth功能
题目地址 https://leetcode.cn/problems/friday-purchases-i/description/ 代码 # Write your MySQL query statement below with t1 as( SELECT *, DAYOFMONTH(purchas ......
[LeetCode] 1363. Largest Multiple of Three 形成三的最大倍数
Given an array of digits digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. If th ......
(△△△)给定 n 个字符串,请对 n 个字符串按照字典序排列。 数据范围: 1 \le n \le 1000 \1≤n≤1000 ,字符串长度满足 1 \le len \le 100 \1≤len≤100
描述 给定 n 个字符串,请对 n 个字符串按照字典序排列。 数据范围: 1 \le n \le 1000 \1≤n≤1000 ,字符串长度满足 1 \le len \le 100 \1≤len≤100 输入描述: 输入第一行为一个正整数n(1≤n≤1000),下面n行为n个字符串(字符串长度≤10 ......
day 1 LeetCode刷题日志
今天的内容是 704 和 27 ovo 704. 二分查找 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target 写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1 Myself C: //左闭右闭 [0,1,2,3] int searc ......
【字典树/trie树】实现高效插入和查询字符串的数据结构
本文是https://www.acwing.com/problem/content/description/837/的总结,有兴趣可以做做 字典树的实现依赖于树结构,有两种操作,1是插入字符串,2是查找字符串。使用idx维护最新的结点下标。如下图,假设我们维护一个 可以看到,我们维护了一个树形结构储 ......
leetcode 11.盛最多水的容器
leetcode 11.盛最多水的容器 第十一题:盛最多水的容器 1.暴力枚举: 会超时,但是做一些条件判断应该可以擦边过 public int maxArea(int[] height) { int max_result = 0; for (int i = 0;i<height.length-1; ......
【Python基础】dict(字典)
简介介绍 dictionary(字典) 是 除列表以外 Python 之中 最灵活 的数据类型 字典同样可以用来 存储多个数据 通常用于存储 描述一个 物体 的相关信息 和列表的区别 列表 是 有序 的对象集合 字典 是 无序 的对象集合 字典用 {} 定义 字典特性 * 字典使用 键值对 存储数据 ......
[LeetCode] 2696. Minimum String Length After Removing Substrings
You are given a string s consisting only of uppercase English letters. You can apply some operations to this string where, in one operation, you can r ......
LeetCode 872
Leaf-Similar Trees Leaf-Similar Trees - LeetCode Thinkings 二叉树无论先中后序遍历,所得叶子节点次序不变. Codes 我采用了非递归的中序遍历方式: /** * Definition for a binary tree node. * st ......
常用容器:动态数组array、列表list、队列 queue、map或字典、 集合、栈等等
一般语言都会提供一些逻辑容器的实现,各个语言的实现方式不同;底层的数学算法应该差不多; # 动态数组, 这个没啥可说的,就是一个数组,满了时候,再创建一个数组,把之前的数组里的数据移过来,销毁之前数组; ......
leetcode 5.最长回文子串
leetcode 5.最长回文子串 第五题:最长回文子串 1.中心拓展: 我们枚举所有的「回文中心」并尝试「扩展」,直到无法扩展为止,此时的回文串长度即为此「回文中心」下的最长回文串长度。我们对所有的长度求出最大值,即可得到最终的答案。拓展分为两种情况,奇数长度和偶数长度,分别拓展一次取较大值,同时 ......
python基础之字符串、列表、字典
1. 字符串 2. 列表 增加 append(obj) insert(index,obj) extend([]) 修改 下标直接赋值 查找 in/not in 删除 del:根据下标进行删除 pop:删除最后一个元素 remove:根据元素的值删除 其他的 3. 元组 // 定义一个元素的元组需要加 ......
1.4 - 循环控制流语句与列表、字典、集合的迭代问题
1.4.1 控制流语句 循环结构for 常和 range() 联用来进行一些列值枚举;range()用来返回一个可迭代对象。 break / continue 控制循环。 循环for/while 也有else子句,else子句的触发条件是:循环的判断条件为False时会进入到else子句执行;但是 ......
[刷题班] LeetCode283. 移动零
题目描述 方法一:时间复杂度O(n2) class Solution { public void moveZeroes(int[] nums) { for (int i = 0; i < nums.length; i ++) { // 指针i为0的时候停止 if (nums[i] == 0) { / ......
[刷题班] LeetCode1002. 查找共用字符
题目描述 思路 关键字:“小写字母”、“出现频率”这些关键字都是为哈希法量身定做的。 求每个字符在所有字符串中最小出现的次数。最小次数为几就在结果集中添加几次该字符。 方法一: class Solution { public List<String> commonChars(String[] wor ......