当前位置:网站首页>今日群里分享的面试题
今日群里分享的面试题
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到起始坐标或者结束坐标到字符串最大长度的一个字符串出来
再进行一次查询公共最长子串
这样你就可以得到修改内容的起始和结束坐标了
然后把这一段截出来就是你修改的内容了

代码实现后续补
边栏推荐
- DDR4 test-2
- JS ternary expression complex condition judgment
- torch. nn. functional. Interpolate function
- [info() method in org.slf4j.logger]
- Redo和Undo的区别
- Salesmartly has some tricks for Facebook chat!
- 集合对象值改变NULL值对象
- 一文读懂C语言中的结构体
- tensorflow报错Could not load dynamic library ‘libcudnn.so.8
- 使用 Kibana Timelion 进行时间序列分析
猜你喜欢

JVM内存模型

118. 杨辉三角

Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference

What is the essential difference between Bi development and report development?

MySQl的基本使用

Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?

Crunch简介、安装,使用Crunch制作密码字典

正则表达式=Regex=regular expression

EasyGBS网络不稳定情况下重复请求视频拉流问题的优化

Native JS creates a calendar - supports mouse wheel scrolling to select months - and can be ported to any framework
随机推荐
JDBC中如何添加事务
产品模块化设计的前世今生
MySQL reports an error can't create table 'demo01 tb_ Student‘ (errno: 150)*
宝,运维100+服务器很头疼怎么办?用行云管家!
mysql 报错 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
Thesis reading [distinctive late semantic graph for video capturing]
Optimization of video streaming with repeated requests in the case of unstable easygbs network
703. 数据流中的第 K 大元素
Introduction and installation of crunch, and making password dictionary with crunch
[Mori city] random talk on GIS data (I)
HLS4ML/vivado HLS 报错解决方案
Flutter 实战-快速实现音视频通话应用
SIP protocol of gb28181
直播HLS协议
MySQl的基本使用
对象的创建
博途V16 获取系统时间转换成字符串
Crunch简介、安装,使用Crunch制作密码字典
【无标题】
Actual combat of flutter - fast implementation of audio and video call application