problem

599. Minimum Index Sum of Two Lists

题意:给出两个字符串数组,找到坐标位置之和最小的相同的字符串。

计算两个的坐标之和,如果与最小坐标和sum相同,那么将这个字符串加入结果res中,如果比sum小,那么sum更新为这个较小值,然后将结果res清空并加入这个字符串。

solution:

class Solution {
public:
vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {
vector<string> res;
int sum = INT_MAX;
for(int i=; i<list1.size(); i++)
{
for(int j=; j<list2.size(); j++)
{
if(list1[i]==list2[j] && (i+j)==sum)
{
res.push_back(list1[i]);
}
else if(list1[i]==list2[j] && (i+j)<sum)
{
sum = i+j;
//res.clear();
vector<string>().swap(res);
res.push_back(list1[i]);
}
}
}
return res; }
};

参考

1. Leetcode_easy_599. Minimum Index Sum of Two Lists;

2. Grandyang;

【Leetcode_easy】599. Minimum Index Sum of Two Lists的更多相关文章

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

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:找到公共元素再求索引和 方法二:索引求和,使 ...

  2. LeetCode 599. Minimum Index Sum of Two Lists (从两个lists里找到相同的并且位置总和最靠前的)

    Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite ...

  3. 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 ...

  4. 599. Minimum Index Sum of Two Lists(easy)

    Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite ...

  5. [LeetCode&Python] Problem 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 ...

  6. 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 fa ...

  7. LC 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 fav ...

  8. 【LeetCode】64. Minimum Path Sum

    Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to b ...

  9. LeetCode 599: 两个列表的最小索引总和 Minimum Index Sum of Two Lists

    题目: 假设 Andy 和 Doris 想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示. Suppose Andy and Doris want to cho ...

随机推荐

  1. css、js文件后的后缀作用是什么?

    文章转自:https://blog.csdn.net/yelbosh/article/details/47303247 <link rel="stylesheet" type ...

  2. Tomcat 配置及优化

    Tomcat配置优化,主要在于优化tomcat运行模式,并发参数和线程数, 以及jvm堆内存和垃圾回收相关参数的优化.下面将逐一介绍. 1. tomcat的3种运行模式 1.1 BIO - 同步阻塞I ...

  3. mysql双主模式方案

    MySQL双主(主主)架构方案   在企业中,数据库高可用一直是企业的重中之重,中小企业很多都是使用mysql主从方案,一主多从,读写分离等,但是单主存在单点故障,从库切换成主库需要作改动.因此,如果 ...

  4. 获取历史K线数据的几个方法

    1.通过已有的股票交易软件下载数据,如果他们是开源结构的,就可以解析他们的K线数据. 2.在互联网上抓取数据 int iStockCode;CString strUrl; 通过OpenUrl.Read ...

  5. mongoose 5.0 链接数据库 代码保存

    const mongoose = require('mongoose'); const dbSrc = 'mongodb://localhost/douban-trailer' mongoose.Pr ...

  6. 15组-Legendary-团队项目总结

    一.项目名称:教室选座系统 二.项目进度表: 项目进度表 活动名称 所属阶段 计划开始时间 计划结束时间 实际结束时间 完成情况 项目方向 项目确立阶段 2019.11.14 2019.11.15 2 ...

  7. 【安卓基础】ViewPager2的入门使用

    之前的项目中使用过ViewPager,被坑过几次.如果你在RecyclerView中的Item使用ViewPager,你绝对会产生莫名其妙的问题,因为ViewPager在同一界面上不能有两个一样的ID ...

  8. Java链接Redis时出现 “ERR Client sent AUTH, but no password is set”

    Java链接Redis时出现 “ERR Client sent AUTH, but no password is set” 异常的原因及解决办法. [错误提示] redis.clients.jedis ...

  9. iSCSI引入FC/SAN

    由 cxemc 在 2013-9-24 上午9:10 上创建,最后由 cxemc 在 2013-9-24 上午9:10 上修改 版本 1 集成iSCSI 和FC SAN有五种常见的方法,各有优缺,适应 ...

  10. [TJOI2013]奖学金 乱搞

    [TJOI2013]奖学金 乱搞 从\(c\)个二元组\((v,w)\)中选出\(n\)个,使其\(v\)的中位数最大的同时使\(w\)和小于等于\(f\),求这个中位数 有点意思.有点像二分答案的思 ...