problem

599. Minimum Index Sum of Two Lists

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

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

solution:

  1. class Solution {
  2. public:
  3. vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {
  4. vector<string> res;
  5. int sum = INT_MAX;
  6. for(int i=; i<list1.size(); i++)
  7. {
  8. for(int j=; j<list2.size(); j++)
  9. {
  10. if(list1[i]==list2[j] && (i+j)==sum)
  11. {
  12. res.push_back(list1[i]);
  13. }
  14. else if(list1[i]==list2[j] && (i+j)<sum)
  15. {
  16. sum = i+j;
  17. //res.clear();
  18. vector<string>().swap(res);
  19. res.push_back(list1[i]);
  20. }
  21. }
  22. }
  23. return res;
  24.  
  25. }
  26. };

参考

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. 生成器调试---send方式

    调试 def creat_num(all_num): a, b = 0, 1 current_num = 0 while current_num < all_num: ret = yield a ...

  2. 简单js的介绍

    JavaScript 简介 JavaScript 是世界上最流行的编程语言. 这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平板电脑和智能手机等设备. JavaScrip ...

  3. E:nth-last-child(n)

    E:nth-last-child(n) 语法: E:nth-last-child(n) { sRules } 说明: 匹配父元素的倒数第n个子元素E,假设该子元素不是E,则选择符无效.大理石平台维修 ...

  4. 006——转载-MATLAB数字与字符之间的转换

    (一)参考文献:https://jingyan.baidu.com/article/5bbb5a1bd8dcb113eba1799d.html (二)数字转换成字符串 第一步在我们的电脑上打开matl ...

  5. spring中少用的注解@primary解析

    这次看下spring中少见的注解@primary注解,例子 @Component public class MetalSinger implements Singer{ @Override publi ...

  6. python 调用未绑定的超类构造方法

    class Bird: def __init__(self): self.hungry = True def eat(self): if self.hungry: print('Aaaaah') se ...

  7. xlrd/xlwt

    操作 xls格式的excel文件 读模块 xlrd import xlrd 打开文件 wb= xlrd.open_workbook('xxxx.xls') 获取excel中的表 ws= wb.shee ...

  8. [English] - 单词阶段1

    百词斩这个app很好玩,尤其是在记忆单词的时候,效果显著. 有的PK赛场也是比较谁的单词翻译提交的快,这个我曾经连胜好几次.

  9. git 文件名大小写不敏感

    1. 通过修改 git 配置: git config core.ignorecase false 2. 强制执行修改文件名命令: 需要重命名已添加到git的文件时,git mv --f oldFile ...

  10. 【原创】go语言学习(十三)struct介绍2

    目录: 方法的定义 函数和方法的区别 值类型和指针类型 面向对象和继承 结构体和json序列化 方法的定义 1.和其他语言不一样,Go的方法采⽤用另外一种方式实现. package main impo ...