gpt4 book ai didi

algorithm - 给定的大括号串判断它是否是一个有效的字符串

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:51:41 25 4
gpt4 key购买 nike

这在 O(n) 中非常简单,但我被要求在小于 O(n) 的时间复杂度内完成。

例如

{({})} is a valid string because each type of opening brace has a matching closing brace. 
while for {{{{)))} this is not as braces doesn't match

最佳答案

如果n是字符串的长度,算法复杂度不能小于O(n),因为如果有字符算法没有检查,就不能确定这个字符是否是大括号与否。所以,它不能小于 O(n)。

关于algorithm - 给定的大括号串判断它是否是一个有效的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18012722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com