合并两个有序整数数组,并去重(输出仍然有序)。
Merge two sorted integer arrays and remove duplicates (output sorted unique array).
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: medium
标签: ByteDance, Two Pointers, Array
目标岗位: Front End Developer, Frontend Engineer
目标公司: ByteDance
参考答案摘要
答案(双指针) 思路: 两个指针 i/j 依次比较,把较小值推进结果;遇到相同值只写一次;写入前检查结果末尾避免重复。 时间/空间 时间:O(n+m) 空间:O(n+m)(输出数组) 参考实现(JavaScript) function mergeSortedUnique(a, b) { let i = 0, j = 0; const res = []; function pushIfNew(x) ...
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。