【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 ...
随机推荐
- linux 安装MySql 5.7.20 操作步骤【亲测】
一. #卸载系统自带的Mariadb[root@master ~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64[root@ ...
- 如何学好java?
忻州seo:如何学好java?想必对于任何一个在学习java的朋友们,都会在学习过程中遇到一些问题.例如:Java反射机制是什么?小编也是学习java编程的,现在给大家简单介绍一下:Java反射机制就 ...
- docker(一) -- docker安装、容器加速、下载、备份
一.docker的 容器是从镜像中创建出来的虚拟实例 容器用来运行实例,是读写层 镜像用来安装程序,是只读层 1. docker的安装和基本操作 安装命令 yum -y update yum inst ...
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part4
Load Data from Test Fixtures in Cypress When creating integration tests with Cypress, we’ll often wa ...
- 学到了林海峰,武沛齐讲的Day31 完 TCP UDP
多用户链接 验证等.学习了思路.还是很有用的..
- ES WIndows 安装 ES与ES-head
一.ES的安装 1.到ES官网下载ES 安装ES前,需要安装JDK1.8以上版本 https://www.elastic.co/downloads/elasticsearch 2.解压ES 3.安装E ...
- 三十四.MySQL主从同步 、主从同步模式
mysql51:192.168.4.51 主 mysql52:192.168.4.52 从 mysql50:192.168.4.50 客户机 1.MySQL一主一从 1.1 51,52 安装m ...
- Poj 2104 K-th Number(主席树&&整体二分)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Case Time Limit: 2000MS Description You are wor ...
- ros平台下python脚本控制机械臂运动
在使用moveit_setup_assistant生成机械臂的配置文件后可以使用roslaunch demo.launch启动demo,在rviz中可以通过拖动机械臂进行运动学正逆解/轨迹规划等仿真运 ...
- JDBC_MySQL8.0.13_连接测试
前言 手贱把MySQL升级到了8.0.13,在IntelliJ IDEA中测试连接不上.因此记录一下,供个人以后参考. 系统环境 win10x64 jkd11 IDEA MySQL 8.10.13 C ...