当前位置:网站首页>今日群里分享的面试题
今日群里分享的面试题
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到起始坐标或者结束坐标到字符串最大长度的一个字符串出来
再进行一次查询公共最长子串
这样你就可以得到修改内容的起始和结束坐标了
然后把这一段截出来就是你修改的内容了
代码实现后续补
边栏推荐
- 科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
- Go Language Advanced
- The use of subplot function in MATLAB
- Mysql查询结果去除换行
- JVM内存模型
- [info() method in org.slf4j.logger]
- Linux下安装Redis,并配置环境
- Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
- ffmpeg AVFrame 转 cv::Mat
- Test self-study people must see: how to find test items in software testing?
猜你喜欢
Test self-study people must see: how to find test items in software testing?
118. Yanghui triangle
Flutter 实战-快速实现音视频通话应用
How to solve the problem of splash screen when the main and sub code streams of easygbs are h.265?
正则表达式=Regex=regular expression
为什么一定要从DevOps走向BizDevOps?
Actual combat of flutter - fast implementation of audio and video call application
精耕渠道共謀發展 福昕攜手偉仕佳傑開展新產品培訓大會
servlet知识点
EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
随机推荐
产品模块化设计的前世今生
Live HLS protocol
使用 Kibana Timelion 进行时间序列分析
ffmpeg 错误码
【let var const】
IPv4 address, subnet mask, gateway
ddr4测试-2
Nat penetration of gb28181
求各种极限的方法
Basic knowledge of audio coding and decoding
Test self-study people must see: how to find test items in software testing?
Why must we move from Devops to bizdevops?
Salesmartly has some tricks for Facebook chat!
Transaction isolation level gap lock deadlock
精耕渠道共謀發展 福昕攜手偉仕佳傑開展新產品培訓大會
Native JS creates a calendar - supports mouse wheel scrolling to select months - and can be ported to any framework
安装sharp报错
Cookie和Session的相关概念
Summary of SQL query de duplication statistics methods
集合对象值改变NULL值对象