comparator leetcode arrays sort

LeetCode 257. 二叉树的所有路径

###题目链接:LeetCode 257. 二叉树的所有路径 ###题意: 给你一个二叉树的根节点 root ,按 任意顺序 ,返回所有从根节点到叶子节点的路径。 ###解题思路: ####递归法 采用递归法,就是一个dfs的过程,在遍历过程中,记录上路径即可。 ####完整代码如下: var re ......
路径 LeetCode 257

LeetCode 110. 平衡二叉树

###题目链接:LeetCode 110. 平衡二叉树 ###题意: 给定一个二叉树,判断它是否是高度平衡的二叉树。 ###解题思路: ####1.递归法: 对于递归法,既然是求树的高度,则应该使用后序遍历的方式, 对于每个节点,求左右子树的高度,比较左右子树的高度差是否小于1,如果不满足,返回fa ......
LeetCode 110

2023-05-15 leetcode周赛题

找出转圈游戏输家 my solution 100% pass class Solution: def circularGameLosers(self, n: int, k: int) -> List[int]: seen = set() now_num = 1 step = 1 seen.add(1 ......
leetcode 2023 05 15

python 报错:TypeError: only integer scalar arrays can be converted to a scalar index

def convolution(initial_img, kernal): img = np.zeros((initial_img.shape[0], initial_img.shape[1])).astype(np.uint8) for x in range(1, initial_img.shap ......
scalar TypeError converted integer python

sort和sorted

sorted() 函数对所有可迭代的对象进行排序操作。 sort 与 sorted 区别: sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作。 list 的 sort 方法返回的是对已经存在的列表进行操作,无返回值,而内建函数 sorted 方法返回的是一个新 ......
sorted sort

leetcode bash题--统计词频

写一个 bash 脚本以统计一个文本文件 words.txt 中每个单词出现的频率。 为了简单起见,你可以假设: words.txt只包括小写字母和 ' ' 。每个单词只由小写字母组成。单词间由一个或多个空格字符分隔。示例: 假设 words.txt 内容如下: the day is sunny t ......
词频 leetcode bash

Java 如何在 Array 和 Set 之间进行转换

概述 在本文章中,我们对如何在 Java 中对 Array 和 Set 进行转换进行一些说明和示例。 这些示例通过使用 Core Java 和一些第三方的转换工具,例如 Guava 和 Apache Commons Collections。 更多有关的文章,请访问:Java - OSSEZ 相关的内 ......
之间 Array Java Set

Java 如何在 Array 和 List 之间进行转换

概述 在本文章中,我们对如何在 Java 中对 Array 和 List 进行转换进行一些说明和示例。 这些示例通过使用 Core Java 和一些第三方的转换工具,例如 Guava 和 Apache Commons Collections。 更多有关的文章,请访问:Java - OSSEZ 相关的 ......
之间 Array Java List

LeetCode刷题记录|LeetCode热题100|136.只出现一次的数字(easy)

题目描述:给你一个 非空 整数数组 nums ,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。你必须设计并实现线性时间复杂度的算法来解决此问题,且该算法只使用常量额外空间。 时间复杂度:O(n) ,其中 n 是数组长度。只需要对数组遍历一次。 空间复杂度:O(1) ......
LeetCode 数字 easy 100 136

leetcode 626 換座位

leetcode 626 換座位 SELECT (CASE WHEN MOD(id, 2) != 0 AND counts != id THEN id + 1 WHEN MOD(id, 2) != 0 AND counts = id THEN id ELSE id - 1 END) AS id, s ......
座位 leetcode 626

leetcode 619 只出現一次的最大數字

leetcode 619 只出現一次的最大數字 select max(num) as num from ( select num as num from MyNumbers group by num having count(num) = 1 ) as mn select if(count(num) ......
leetcode 619

vue sort 排序方法

1、数据排序 var arry = [9,5,6,7,5,6,3,1,0] arry.sort() // [0, 1, 3, 5, 5, 6, 6, 7, 9] 2、对象排序 var list=[{name:'张三',age:12},{name:'李四','age:23}]; list.sort(( ......
方法 sort vue

leetcode 1679

1.排序双指针 先排序 sort(nums.begin(),nums.end()); 在双指针查找 while(left<right){ if(nums[left]+nums[right]<k){ left++; }else if(nums[left]+nums[right]>k){ right-- ......
leetcode 1679

leetcode-349. 两个数组的交集

return nums1.Intersect(nums2); 题意:给定两个数组,编写一个函数来计算它们的交集。 c#可以用linq自带的方法返回,顺便看了下微软的内部实现: private static IEnumerable<TSource> IntersectIterator<TSource> ......
数组 交集 leetcode 两个 349

sort vs sorted

The primary difference between the two is that list.sort() will sort the list in-place, mutating its indexes and returning None, whereas sorted() will ......
sorted sort vs

[LeetCode] 2437. Number of Valid Clock Times

You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is  ......
LeetCode Number Clock Valid Times

2023-05-08:我们定义了一个函数 countUniqueChars(s) 来统计字符串 s 中的唯一字符, 并返回唯一字符的个数。 例如:s = “LEETCODE“ ,则其中 “L“, “T

2023-05-08:我们定义了一个函数 countUniqueChars(s) 来统计字符串 s 中的唯一字符, 并返回唯一字符的个数。 例如:s = "LEETCODE" ,则其中 "L", "T","C","O","D" 都是唯一字符, 因为它们只出现一次,所以 countUniqueChar ......

LeetCode198. 打家劫舍

class Solution { public: int f[110],g[110];//分别表示第i个房屋偷,不偷的最大价值 int rob(vector<int>& nums) { int n=nums.size(); for(int i=1;i<=n;i++) { g[i]=max(f[i-1 ......
打家劫舍 LeetCode 198

LeetCode 76. 最小覆盖子串

###题目链接:LeetCode 76. 最小覆盖子串 ###题意: 给你一个字符串 s 、一个字符串 t 。返回 s 中涵盖 t 所有字符的最小子串。如果 s 中不存在涵盖 t 所有字符的子串,则返回空字符串 "" 。 ###解题思路: 方法:采用双指针的方法(或者叫滑动窗口) 双指针算法(滑动窗 ......
盖子 LeetCode 76

Python-5高阶函数“map”、“reduce”、“filter”、“sorted”

1.map函数:map(func, iterable) ①功能:处理数据 把iterable中的数据一个一个拿出来,扔到func中做处理,通过调用迭代器来返回参数。 ②参数:func:函数(自定义,或者内置函数) iterable:可迭代对象(容器数据,range,迭代器) ③返回值:迭代器(需要迭 ......
高阶 函数 Python filter reduce

前端传数组,后端可用list接收,apifox对应用数据结构-array

一开始apifox的body设置如图 idea报错: Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of ......
数据结构 数组 前端 结构 数据

leetcode 101 对称二叉树 Simple

##题目 给你一个二叉树的根节点 root , 检查它是否轴对称。 输入:root = [1,2,2,3,4,4,3] 输出:true 输入:root = [1,2,2,null,3,null,3] 输出:false ##题解 考察二叉树的遍历, 使用广度优先 BFS 方法. BFS 的关键在于使用 ......
leetcode Simple 101

LeetCode 473 火柴拼正方形

LeetCode | 473.火柴拼正方形 你将得到一个整数数组 matchsticks ,其中 matchsticks[i] 是第 i 个火柴棒的长度。你要用 所有的火柴棍 拼成一个正方形。你 不能折断 任何一根火柴棒,但你可以把它们连在一起,而且每根火柴棒必须 使用一次 。 如果你能使这个正方形 ......
正方形 正方 火柴 LeetCode 473

python学习笔记9(地图、柱状图、sort函数、动态柱状图)

1. 折线图案例 对于大量数据,json的格式不规范,想要知道json的格式以及层次可以使用以下网站进行查看。P103~104 懒人工具-json 在线解析-在线JSON格式化工具-json校验-程序员必备 (ab173.com) 2.地图可视化 """ 地图可视化 """ from pyechar ......
函数 地图 笔记 动态 python

LeetCode 周赛 344(2023/05/07)手写递归函数的固定套路

本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 提问。 大家好,我是小彭。 今天下午有力扣杯战队赛,不知道官方是不是故意调低早上周赛难度给选手们练练手。 往期周赛回顾:LeetCode 单周赛第 343 场 · 结合「下一个排列」的贪心构造问题 周赛概览 T1. ......
套路 函数 LeetCode 2023 344

LeetCode 15. 三数之和

###题目链接:LeetCode 15. 三数之和 ###题意: 在给定的数组中,找出三个数(三个数不重复)使得他们相加的和为 0 ,同时答案中不能有重复的答案 ###解题思路: ####完整代码如下: //双指针做法首先要有序 // 解法一 最优解,双指针 + 排序 func threeSum(n ......
之和 LeetCode 15

LeetCode 18. 四数之和

###题目链接:LeetCode 18. 四数之和 ###题意: 本题思路与LeetCode 15. 三数之和思路完全一样,只是多加了一层for循环 ###解题思路: ####完整代码如下: func fourSum(nums []int, target int) [][]int { // 四元组, ......
之和 LeetCode 18

LeetCode 383. 赎金信

###题目链接:LeetCode 383. 赎金信 ###题意: 给你两个字符串:ransomNote 和 magazine ,判断 ransomNote 能不能由 magazine 里面的字符构成。 ###解题思路: 首先利用map记录magazine 中所有出现的字母,key是单个字母,valu ......
LeetCode 383

LeetCode 454. 四数相加 II

###题目链接:LeetCode 454. 四数相加 II ###题意: 给定四个数组,找出在四个数组中,各取一个数,使得四个数相加和为0 ###解题思路: 本题给出的是四个独立的数组,只要找到nums1[i] + nums2[j] + nums3[k] + nums4[l] = 0就可以,不用考虑 ......
LeetCode 454 II

LeetCode 516. 最长回文子序列

class Solution { public: int f[1010][1010];//f[i][j]表示s[i~j]之间的最长序列 int INF=0x3f3f3f3f; int longestPalindromeSubseq(string s) { int n=s.size(); s=' '+ ......
回文 序列 LeetCode 516