文章 评论 浏览 29
暴力一点吧。
var intersect = function(nums1, nums2) { let result = []; for(let i = 0; i < nums1.length; i++) { for(let j = 0; j < nums2.length; j++) { if(nums1[i] == nums2[j]) { nums2.splice(j,1); result.push(nums1[i]); break; } } } return result; }
const findStr = (str, t) => { if (t.length > str.length) return -1; for (let index = 0; index < str.length - t.length + 1; index++) { const cur = str.slice(index, index + t.length); if (cur === t) { return index; } } }; console.log(find('asdfg', 'sdf'));
文章 0 评论 0
接受
暴力一点吧。
第 59 题:给定两个数组,写一个方法来计算它们的交集