Python 刷Leetcode题库,顺带学英语单词(50)

本文探讨了两个计算机科学问题:如何在线性时间内找到数组中大小为k的滑动窗口内的最大值,以及如何判断两个字符串是否是异位词。滑动窗口最大值问题涉及数组处理和动态窗口的概念,而异位词判断则涉及到字符串的字符排序和比较。这两个问题都是算法设计中的常见挑战,对于提高编程效率和优化解决方案至关重要。

Sliding Window Maximum

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window.   [#239]

Example:
Input: nums = [1,3,-1,-3,5,3,6,7], and k = 3
Output: [3,3,5,5,6,7]
Explanation:
Window position         Max
---------------                 -----
[1 3 -1] -3 5 3 6 7        3
1 [3 -1 -3] 5 3 6 7        3
1 3 [-1 -3 5] 3 6 7        5
1 3 -1 [-3 5 3] 6 7        5
1 3 -1 -3 [5 3 6] 7        6
1 3 -1 -3 5 [3 6 7]        7

Note:
You may assume k is always valid, 1 ≤ k ≤ input array's size for non-empty array.
Follow up:
Could you solve it in linear time?


Valid Anagram

Given two strings s and t , write a function to determine if t is an anagram of s.    [#242]

Examples:
Input: s = "anagram", t = "nagaram"
Output: true
Input: s = "rat", t = "car"
Output: false

Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hann Yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值