【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 ...
随机推荐
- 生成器调试---send方式
调试 def creat_num(all_num): a, b = 0, 1 current_num = 0 while current_num < all_num: ret = yield a ...
- 简单js的介绍
JavaScript 简介 JavaScript 是世界上最流行的编程语言. 这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平板电脑和智能手机等设备. JavaScrip ...
- E:nth-last-child(n)
E:nth-last-child(n) 语法: E:nth-last-child(n) { sRules } 说明: 匹配父元素的倒数第n个子元素E,假设该子元素不是E,则选择符无效.大理石平台维修 ...
- 006——转载-MATLAB数字与字符之间的转换
(一)参考文献:https://jingyan.baidu.com/article/5bbb5a1bd8dcb113eba1799d.html (二)数字转换成字符串 第一步在我们的电脑上打开matl ...
- spring中少用的注解@primary解析
这次看下spring中少见的注解@primary注解,例子 @Component public class MetalSinger implements Singer{ @Override publi ...
- python 调用未绑定的超类构造方法
class Bird: def __init__(self): self.hungry = True def eat(self): if self.hungry: print('Aaaaah') se ...
- xlrd/xlwt
操作 xls格式的excel文件 读模块 xlrd import xlrd 打开文件 wb= xlrd.open_workbook('xxxx.xls') 获取excel中的表 ws= wb.shee ...
- [English] - 单词阶段1
百词斩这个app很好玩,尤其是在记忆单词的时候,效果显著. 有的PK赛场也是比较谁的单词翻译提交的快,这个我曾经连胜好几次.
- git 文件名大小写不敏感
1. 通过修改 git 配置: git config core.ignorecase false 2. 强制执行修改文件名命令: 需要重命名已添加到git的文件时,git mv --f oldFile ...
- 【原创】go语言学习(十三)struct介绍2
目录: 方法的定义 函数和方法的区别 值类型和指针类型 面向对象和继承 结构体和json序列化 方法的定义 1.和其他语言不一样,Go的方法采⽤用另外一种方式实现. package main impo ...