当前位置:网站首页>今日群里分享的面试题
今日群里分享的面试题
2022-07-01 18:46:00 【王元肉】
像往常一样,睡前点开学习交流群,今天群里居然没在摸鱼,在讨论面试题,一下子就提起了我的兴趣,蹲守了一下,发了三个面试题,我就试着尝试了一下。
1
题


我的解
let arr = [4, 5, 5, 3, 2, 8, 7];
let arr2 = [60, 90, 80, 110, 120, 90, 100, 90, 100, 100];
const fn = function(arr) {
let min = arr[arr.length - 1];
let result = [];
arr.reverse().forEach((item, index) => {
if (item <= min) {
min = item;
result.push(arr.length - 1 - index);
}
});
return result.reverse();
};
console.log(fn(arr));
console.log(fn(arr2));
2.
题


我的解
const arr = [1, 2, 3, 4, 1, 2];
const obj2 = {
value: 0,
child: [],
};
const fn = function(arr, obj) {
if (arr.length >= 2) {
obj.child.push({
value: arr[0], child: [] });
obj.child.push({
value: arr[1], child: [] });
fn(arr.slice(2, arr.length), obj.child[0]);
fn(arr.slice(3, arr.length), obj.child[1]);
} else if (arr.length === 1) {
obj.child.push({
value: arr[0], child: [] });
fn(arr.slice(2, arr.length), obj.child[0]);
}
};
fn(arr, obj2);
console.log(obj2);
const arr2 = [];
const fn2 = function(obj2, sum) {
sum = sum + obj2.value;
if (obj2.child.length === 1) {
fn2(obj2.child[0], sum);
} else if (obj2.child.length === 2) {
fn2(obj2.child[0], sum);
fn2(obj2.child[1], sum);
} else {
arr2.push(sum);
}
};
fn2(obj2, 0);
console.log(arr2.sort()[arr2.length - 1]);
3.
题

我的思路
当你给我这个问题,我想到的是查询字符串中的公共最长子串
从而得到修改内容的起始坐标或者结束坐标
然后再截取0到起始坐标或者结束坐标到字符串最大长度的一个字符串出来
再进行一次查询公共最长子串
这样你就可以得到修改内容的起始和结束坐标了
然后把这一段截出来就是你修改的内容了

代码实现后续补
边栏推荐
- 新增订单如何防止重复提交
- [Mori city] random talk on GIS data (I)
- Test self-study people must see: how to find test items in software testing?
- 测试自学人必看:软件测试如何找测试项目?
- Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
- 使用 Kibana Timelion 进行时间序列分析
- Wireshark packet analysis TCP, FTP
- 对象的创建
- Remove line breaks from MySQL query results
- Ubuntu14 install MySQL and configure root account local and remote access
猜你喜欢
随机推荐
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function
What is the essential difference between Bi development and report development?
求各种极限的方法
118. 杨辉三角
The use of subplot function in MATLAB
Case sharing: basic networking configuration of QinQ
Summary of SQL query de duplication statistics methods
DDR4 test-2
IPv4 address, subnet mask, gateway
[info() method in org.slf4j.logger]
118. Yanghui triangle
Define dichotomy lookup
GC垃圾回收
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
一文读懂C语言中的结构体
Analysis of GetMessage underlying mechanism
Instagram 为何从内容共享平台变成营销工具?独立站卖家如何利用该工具?
集合对象值改变NULL值对象
博途V16 获取系统时间转换成字符串
MySQl的基本使用









