【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 ...
随机推荐
- [bzoj 2393] Cirno的完美算数教室 (容斥原理+dfs剪枝)
题目描述 CirnoCirnoCirno发现了一种bakabakabaka数,这种数呢只含有222和999两种数字 现在CirnoCirnoCirno想知道[L,R][L,R][L,R]中有多少个数能 ...
- POJ-2689-Prime Distance(素数区间筛法)
链接: https://vjudge.net/problem/POJ-2689 题意: The branch of mathematics called number theory is about ...
- 把hdfs数据写入到hbase表
功能:把hdfs上的数据写入到hbase表. hadoop的mapreduce输出要导入到hbase表,最好先输出HFile格式,再导入hbase,因为HFile是hbase的内部存储格式,所以导入效 ...
- Spring AOP的作用,动态代理模式
AOP即面向切面编程.AOP是基于代理模式的. 代理模式: 当我们需要修改一个类,在类中加入代码时,为了不破坏这个类的封装性.可以使用代理模式,建立一个代理类. 比如:修改需求,在调用UserCont ...
- 列出python中可变数据类型和不可变数据类型,并简述原理
可变类型(mutable):变量进行append.+=等这种操作后 == 改变了变量的值,而不会新建一个对象,变量引用的对象的地址也不会变化,不过对于相同的值的不同对象,在内存中则会存在不同的对象,即 ...
- fixedFluxPressure边界条件【转载】
转载自:http://blog.sina.com.cn/s/blog_e256415d0102vikh.html fixedFluxPressure是OpenFOAM较新的一个边界条件,表示边界处压力 ...
- synchronized的原理与使用
理论层面: 内置锁与互斥锁 修饰普通方法.修饰静态方法.修饰代码块 demo如下: package com.roocon.thread.t3; public class Sequence { priv ...
- Arts打卡第6周
Algorithm.主要是为了编程训练和学习. 每周至少做一个 leetcode 的算法题(先从Easy开始,然后再Medium,最后才Hard). 进行编程训练,如果不训练你看再多的算法书,你依然不 ...
- Sollin算法的C++实现 BY gremount
Sollin算法可以看作是Kruskal算法和Prim算法的综合 基本思想是: 1. 从所有节点都孤立的森林开始,通过合并树来得到最小生成树 2. 每次合并树的边都是用最小权重的割边 程序具体实现思路 ...
- Beta冲刺(2/4)
队名:福大帮 组长博客链接:https://www.cnblogs.com/mhq-mhq/p/11990570.html 作业博客 : https://edu.cnblogs.com/campus/ ...