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?

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





