python算法题库,leetcode 208 python3
202快乐数 编写一个算法来判断一个数是不是“快乐数”。 python算法题库。一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1。如果可以变为
时间:2023-09-21  |  阅读:22
python算法题库,leetcode 203 python3
203 删除链表中等于给定值 val 的所有节点。 示例: python算法题库?输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3->4->5 # Definition for singly-linked list. class ListNode:def __init__(self, x):self.val = xself.next &#
时间:2023-09-21  |  阅读:23
python算法题库,leetcode 1227 python
class Solution:def nthPersonGetsNthSeat(self, n: int) -> float:a = 1b =0.5if n == 1:return areturn b 解答过程:
时间:2023-09-21  |  阅读:26
python算法题库,leetcode 1223 python
题目要求:https://leetcode-cn.com/problems/dice-roll-simulation/ 思路: i: 第i次扔 j: 扔出j k:此时j连续出现的次数k 状态转移方程: 当k>1时,dp[i][j][k]=dp[i-1][j][k-1] 当k=1时,dp[i][j][k]=d
时间:2023-09-21  |  阅读:21
python算法题库,leetcode 1222 python
题目要求: https://leetcode-cn.com/problems/queens-that-can-attack-the-king/ 思路: 首先可以攻击到的queen只有x=king(x),y=king(y),y-king(y)=x-king(x) 以国王为起点往八个方向迭代,循环结束条件为出界((x < 0 || x >= 8) |
时间:2023-09-21  |  阅读:25
python算法题库,leetcode 1221 python
题目要求: https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/ class Solution:def balancedStringSplit(self, s: str) -> int:count,res = 0,0for si in s:if si == 'L':count += 1else:count -= 1if count
时间:2023-09-21  |  阅读:23
python算法题库,leetcode 1218 python
题目要求: https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-difference/submissions/ dict用法: https://www.runoob.com/python/att-dictionary-get.html class Solution:def longestSubsequence(self, arr: List[int], difference
时间:2023-09-21  |  阅读:24
python算法题库,leetcode 1209 python
题目要求:https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/submissions/ 思路: 每次删除掉第一次出现的连续k个相同的字符,然后进行下次递归即可。 class Solution:def removeDuplicates(self, s: str, k: int) -> st
时间:2023-09-21  |  阅读:24
python算法题库,leetcode 1217 python
题目要求: https://leetcode-cn.com/problems/unique-number-of-occurrences/submissions/ from collections import Counter class Solution:def uniqueOccurrences(self, arr: List[int]) -> bool:c = Counter(arr).values()print(c)if len(c) == len
时间:2023-09-21  |  阅读:30
python算法题库,leetcode 1189 python
题目要求: https://leetcode-cn.com/problems/maximum-number-of-balloons/ class Solution:def maxNumberOfBalloons(self, text: str) -> int:d = collections.Counter(text)return min(d['b'], d['a'], d['l'] // 2, d['o']
时间:2023-09-21  |  阅读:24

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息