[LeetCode]599. Minimum Index Sum of Two Lists

[STM32]HAL STM32F103 软件I2C读写MPU6050(附DMP库移植) 本文介绍了如何在STM32F103C8T6上通过I2C协议与MPU6050传感器通信并实现DMP功能。首先,使用STM32CubeMX配置项目,设置时钟和I2C接口。然后,编写软件I2C协议的读写函数与MPU6050交互。接着,移植DMP库并进行必要修改,获取加速度计和陀螺仪数据,并将其转换为欧拉角显示在OLED上。最后,利用Keil的逻辑分析仪监测I2C时序。 阅读详情

[LeetCode]599. Minimum Index Sum of Two Lists

题目描述

这里写图片描述

思路

哈希,先存list1的结果
然后扫list2,有与list1相同的存入哈希,同时保留最小和
遍历哈希,值为最小和的string存入数组返回

代码

#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>

using namespace std;

class Solution {
public:
    vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {
        unordered_map<string, int> um, repeat;
        int min_sum = list1.size() + list2.size();
        for (int i = 0; i < list1.size(); ++i) {
            um[list1[i]] = i;
        }
        for (int i = 0; i < list2.size(); ++i) {
            if (um.count(list2[i])) {
                repeat[list2[i]] = i + um[list2[i]];
                min_sum = min(min_sum, i + um[list2[i]]);
            }
        }
        vector<string> res;
        for (auto p : repeat)
            if (p.second == min_sum) res.push_back(p.first);

        return res;
    }
};

int main() {
    Solution s;
    vector<string> list1 = { "Shogun", "Tapioca Express", "Burger King", "KFC" },
        list2 = { "Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun" },
        res = {};
    res = s.findRestaurant(list1, list2);
    for (string str : res)
        cout << str << endl;
    cout << endl;

    system("pause");
    return 0;
}
IDC 数据中心工程师面试题汇总 (适用于:IDC运维、机房值班、机房工程师、机柜运维、IDC基础设施、IDC网络运维岗) 阅读详情

相关推荐

惊呆了!Oracle 11g从入门到放弃的保姆级指南(新手必看)

本文为Oracle 11g数据库新手提供了一份详尽的入门指南。内容涵盖从安装配置、SQL*Plus工具使用、核心的SQL增删改查操作,到事务、索引等进阶概念的解析。文章旨在帮助初学者避开常见陷阱,快速掌握这一经典关系型数据库管理系统的基本操作与核心技能,实现从入门到上手。

ooo22的博客 266

[leetcode]599. Minimum Index Sum of Two Lists

[leetcode]599. Minimum Index Sum of Two Lists Analysis ummm~—— [ummmm~] Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants repre...

weixin_32135877的博客 119

配置 Druid 数据源及密码加密-SpringBoot 实战基础

在SpringBoot中配置 Druid 数据源及密码加密的方法前文集成 MyBatis Plus,实现了一组增删改查接口。在启动服务时,从控制台中可以看出 Spring Boot 默认使用 Hikari 作为数据库连接池,Hikari性能很优秀。在国内使用较多的连接池还属阿里开源的 Druid,中文发音为德鲁伊。Druid 结合了 C3P0、DBCP 等 DB 池的优点,同时还加入了日志监控,可以很好的监控 DB 池连接和 SQL 的执行情况。...

m0_67698950的博客 954

leetcode 599. Minimum Index Sum of Two Lists

目录 一、问题描述 二、代码实现 1、暴力法 2、使用HashMap https://leetcode.com/problems/minimum-index-sum-of-two-lists/ 从两个人喜欢的餐厅列表中找到共同喜欢并下标之和最小的餐厅(如果有多个则将它们都返回) 一、问题描述 测试用例: Example 1: Input: ["Shogun", "T...

小景的博客 245

深入理解光流法外推雷达回波

背景介绍 鉴于本人实在太过疲惫和劳累,一些简单的便于理解的废话就不在记录,耗费两天时间研究了一下光流法,本帖用于记录学习过程中源码的难点细节。 使用光流预测的核心有两个利用多张连续回波图像(变分)或者相邻两张回波图(交叉相关,LK等)计算出光流场(速度矢量场),之后利用半拉格朗日方法进行外推。 半拉格朗日方法 三时间步半拉格朗日方法,其核心公式如下 但这个有点难理解,但看一维的图就很好理解 它的核心就是迭代求Am(位移矢量),如果理解困难的话,其实质上就是通过未来迭代(猜)出当前时刻的Am找到过去的假设

weixin_44695861的博客 6034

win11本地部署 DeepSeek-R1 大模型!免费开源,媲美OpenAI-o1能力,断网也能用

是否安装成功,然后直接运行部署deepseek-r1的命令。,出现下面界面即为安装成功。在cmd窗口中先输入。

记录学习编程的日常 2992

【Leetcode】599. Minimum Index Sum of Two Lists

题目地址: https://leetcode.com/problems/minimum-index-sum-of-two-lists/ 给定两个字符串数组AAA和BBB,要求返回两个数组的交集中下标和最小的那些字符串。有可能有多个答案,所以要求返回数组。 不妨设AAA的长度小于等于BBB,接着用一个哈希表记录AAA中字符串及每个字符串下标,然后遍历BBB,若发现哈希表存了当前字符串,则判断下标和是否更小,若更小,则更新最小下标和,并清空答案,并把这个字符串加进去;若相等,则不用清空答案,直接加进去;若更大,

数学、算法爱好者的博客 191

别再只玩积木了!用乐高EV3和官方软件,手把手教你做个能巡线的小车(附完整代码)

本文详细介绍了如何利用乐高EV3套件和官方软件制作智能巡线机器人,从硬件组装到软件编程全面覆盖。通过传感器原理讲解、控制算法调试等工程化细节,帮助读者掌握机器人开发的核心理念,特别适合STEAM教育和硬件编程爱好者实践。

weixin_30776273的博客 449

【LeetCode】599.Minimum Index Sum of Two Lists(Easy)解题报告

【LeetCode】599.Minimum Index Sum of Two Lists(Easy)解题报告题目地址:https://leetcode.com/problems/minimum-index-sum-of-two-lists/description/ 题目描述:   Suppose Andy and Doris want to choose a restaurant for di

郝春雨的博客 256

MIKE水动力笔记7_实测数据与模型输出结果的拟合对比

上一博文【MIKE水动力笔记6】主要讲解如何自己制作实测数据的时间序列文件dfs0,而本博文讲解如何进行实测数据与模型输出结果的拟合对比。

晏长街的博客 1万+

6、深入解析Microsoft 365核心服务对比与迁移策略

本文深入解析了Microsoft 365的核心服务,包括身份和设备管理、现代设备配置体验、Exchange和SharePoint的迁移策略以及Microsoft Teams的协作功能。同时探讨了迁移过程中需要考虑的安全控制措施,为组织规划和实施云迁移项目提供了全面的指导和建议。

k8s6orchestrator的博客 107

LeetCode //C - 599. Minimum Index Sum of Two Lists

【代码】LeetCode //C - 599. Minimum Index Sum of Two Lists。

Made in Code 837

华为OD新系统机试真题 2026.5.10 - 美观的灯笼

华为OD新系统机试真题【美观的灯笼】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【美观的灯笼】

qq_45776114的博客 640

LeetCode599. Minimum Index Sum of Two Lists [C++]

Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to help them find out theircommon interestwith the...

iuvgood 239

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

[leetcode] 599. Minimum Index Sum of Two Lists

Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to help them find out their common interest with th

kangbin825的专栏 1960

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

LeetCode 599. Minimum Index Sum of Two Lists

599. Minimum Index Sum of Two Lists

Silicat's Blog 334

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

leetcode 599. Minimum Index Sum of Two Lists | 599. 两个列表的最小索引总和

题目 https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists/ 题解 思路和题解一致,用 map 搞定。效率低可能是因为建了两个 map。 import java.util.ArrayList; import java.util.HashMap; import java.util.Map; class Solution { public String[] findRestaurant(String[] list1, Stri

寒泉 5万+

【Leetcode_easy】599. Minimum Index Sum of Two Lists

problem 599. Minimum Index Sum of Two Lists 题意:给出两个字符串数组,找到坐标位置之和最小的相同的字符串。 计算两个的坐标之和,如果与最小坐标和sum相同,那么将这个字符串加入结果res中,如果比sum小,那么sum更新为这个较小值,然后将结果res清空并加入这个字符串。 solution: class Solution { public...

weixin_30588907的博客 102

【LeetCode】599. Minimum Index Sum of Two Lists

Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to help them find out their common interest with the l

a342500329a的专栏 408

Leetcode 599 Minimum Index Sum of Two Lists

Leetcode 599 Minimum Index Sum of Two Listsclass Solution { public: vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) { unordered_map<string,int> nameAndOrder;//li

自己的学习笔记 363

LeetCode-599. Minimum Index Sum of Two Lists

Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to help them find out their common interest with th

NOadu的专栏 588

Leetcode599.Minimum Index Sum of Two Lists

假设Andy和Doris想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示。 你需要帮助他们用最少的索引和找出他们共同喜爱的餐厅。 如果答案不止一个,则输出所有答案并且不考虑顺序。 你可以假设总是存在一个答案。 示例 1: 输入: ["Shogun", "Tapioca Express", "Burger Ki...

Ha12312的博客 121
上一篇: [LeetCode]598. Range Addition II
下一篇: [LeetCode]628. Maximum Product of Three Numbers
charon____
博客等级 码龄11年 3粉丝 202原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值