题目:原题链接(中等)
标签:数组、哈希表
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
---|---|---|---|
Ans 1 (Python) | O ( N ) O(N) O(N) | L ( N ) L(N) L(N) | 160ms (87.84%) |
Ans 2 (Python) | |||
Ans 3 (Python) |
解法一:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22class Solution: def findLongestSubarray(self, array: List[str]) -> List[str]: dic = {0: 0} count = 0 ans_idx, ans_val = (0, 0), 0 for i in range(len(array)): if array[i].isnumeric(): count += 1 else: count -= 1 if count in dic: l, r = dic[count], i + 1 if r - l + 1 > ans_val: ans_idx, ans_val = (l, r), r - l + 1 else: dic[count] = i + 1 # print(i, count, ans_idx, ans_val, dic) return array[ans_idx[0]:ans_idx[1]]
最后
以上就是友好麦片最近收集整理的关于LeetCode题解(面试17.05):字母与数字(Python)的全部内容,更多相关LeetCode题解(面试17内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复