【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:
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的更多相关文章
- 【LeetCode】599. Minimum Index Sum of Two Lists 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:找到公共元素再求索引和 方法二:索引求和,使 ...
- 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 ...
- 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 ...
- 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 ...
- [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 ...
- 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 ...
- 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 ...
- 【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 ...
- LeetCode 599: 两个列表的最小索引总和 Minimum Index Sum of Two Lists
题目: 假设 Andy 和 Doris 想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示. Suppose Andy and Doris want to cho ...
随机推荐
- 聊聊MVCC多版本并发控制
一.介绍 MVCC只在RR和RC 2个隔离级别下才能工作.MySQL的大多数事务存储引擎实现的都不是简单的行级锁机制.基于提升并发性能的考虑,它们一般都同时实现了MVCC. 通俗的来讲,MVCC是行级 ...
- Jmeter+Jenkins持续集成(一、环境准备)
1.安装JDK (1)下载JDK,jdk8u181-x64.dmg 并进行安装 (2)配置环境变量.打开配置文件 open -e .bash_profile.按照自己的安装路径进行配置. JAVA_H ...
- 金蝶二次开发C#
1 建立C#类库项目 2 引用EBOS组建Kingdee.K3.BOS.PlugInModel 3 示例代码 usingSystem; usingSystem.Collections.Generic; ...
- Django --- 路由层(urls)
目录 1.orm表关系如何建立 2.django请求生命周期流程图 3.urls.py路由层 4.路由匹配 5.无名分组 6.有名分组 7.反向解析 8.路由分发 9.名称空间 10.伪静态 11.虚 ...
- Mac+Appium+Python+Pycharm环境搭建
为什么优先选择Mac做自动化测试? 1.既可以做iOS端的测试也可以进行Android端测试 2.Mac运行效率相对于Win要高很多,可以真正发挥appium的功能 以下是在Mac上完整搭建过程 一. ...
- LOJ P10114 数星星 stars 题解
每日一题 day7 打卡 Analysis 树状数组 由于题目中给的数据是按y轴排序,我们只需构建x轴的树状数组,也就是说我们只需统计星星i之前一共有多少个x坐标小于或等于Xi的星星,这个数值也就是星 ...
- Poj 2104 K-th Number(主席树&&整体二分)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Case Time Limit: 2000MS Description You are wor ...
- Xmind8安装
现在新版安装极其简单.是deb安装包Xmind8安装小书匠 kindle 参照官网安装方法,在此记录下来,方便自己查找. 流程: 55ccaad0655d256ac5fb9fea8aa8569d.pn ...
- wepy项目的学习
使用Promise 开发实时编译 wepy build --watch 安装依赖 cd myproject npm install 安装(更新) wepy 命令行工具. npm install wep ...
- [bzoj 5332][SDOI2018]旧试题
传送门 Description \[ \sum_{i=1}^A\sum_{j=1}^B\sum_{k=1}^Cd(ijk) (\mathrm{mod\:} 10^9+7) \] 其中 \(d(ijk) ...