Input: strs = [“dog”,”racecar”,”car”] Output: “” Explanation: There is no common prefix among the input strings.
Constraints:
1 <= strs.length <= 2000 <= strs[i].length <= 200 * strs[i] consists of only lower-case English letters.
题目大意:
字符串列表的最长前缀
算法思路:
N/A
注意事项:
求最小值len初始值用最大值而不是0
char = strs[0][i]而不是char = strs[i]
Python代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
deflongestCommonPrefix(self, strs: List[str]) -> str: min_len, res = sys.maxsize, '' for s in strs: min_len = min(min_len, len(s)) for i in range(min_len): char = strs[0][i] same_char = True for j in range(1, len(strs)): if char != strs[j][i]: same_char = False break ifnot same_char: break res += char return res
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.