Given two lists and B, and B is an anagram of AB is an anagram of A means B is made by randomizing the order of the elements in A.

We want to find an index mapping P, from A to B. A mapping P[i] = j means the ith element in A appears in B at index j.

These lists A and B may contain duplicates. If there are multiple answers, output any of them.

For example, given

A = [12, 28, 46, 32, 50]
B = [50, 12, 32, 46, 28]

We should return

[1, 4, 3, 2, 0]

as P[0] = 1 because the 0th element of A appears at B[1], and P[1] = 4 because the 1st element of Aappears at B[4], and so on.

Note:

  1. A, B have equal lengths in range [1, 100].
  2. A[i], B[i] are integers in range [0, 10^5].

这道题给了我们两个数组A和B,说是A和B中的数字都相同,但是顺序不同,有点类似错位词的感觉。让我们找出数组A中的每个数字在数组B中的位置。这道题没有太大的难度,用个HashMap建立数组B中的每个数字和其位置之间的映射,然后遍历数组A,在HashMap中查找每个数字的位置即可,参见代码如下:

class Solution {
public:
vector<int> anagramMappings(vector<int>& A, vector<int>& B) {
vector<int> res;
unordered_map<int, int> m;
for (int i = ; i < B.size(); ++i) m[B[i]] = i;
for (int num : A) res.push_back(m[num]);
return res;
}
};

类似题目:

Find All Anagrams in a String

Valid Anagram

Anagrams

[LeetCode] Find Anagram Mappings 寻找异构映射的更多相关文章

  1. 【LeetCode】760. Find Anagram Mappings 解题报告

    [LeetCode]760. Find Anagram Mappings 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/find ...

  2. Hibernate One-to-One Mappings 一对一关系映射

    Hibernate One-to-One Mappings 一对一关系映射 关键:一对一关系映射和多对一关系映射非常像.仅仅是unique 属性值为 true 样例:一个员工仅仅能有一个地址. Hib ...

  3. Leetcode(4)寻找两个有序数组的中位数

    Leetcode(4)寻找两个有序数组的中位数 [题目表述]: 给定两个大小为 m 和 n 的有序数组 nums1 和* nums2. 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O( ...

  4. 【python】Leetcode每日一题-寻找旋转排序数组中的最小元素

    [python]Leetcode每日一题-寻找旋转排序数组中的最小元素 [题目描述] 已知一个长度为 n 的数组,预先按照升序排列,经由 1 到 n 次 旋转 后,得到输入数组.例如,原数组nums ...

  5. 【python】Leetcode每日一题-寻找旋转排序数组中的最小元素2

    [python]Leetcode每日一题-寻找旋转排序数组中的最小元素2 [题目描述] 已知一个长度为 n 的数组,预先按照升序排列,经由 1 到 n 次 旋转 后,得到输入数组.例如,原数组nums ...

  6. LeetCode 760. Find Anagram Mappings

    原题链接在这里:https://leetcode.com/problems/find-anagram-mappings/description/ 题目: Given two lists Aand B, ...

  7. 【LeetCode】760. Find Anagram Mappings 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...

  8. [LeetCode] Valid Anagram 验证变位词

    Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...

  9. [LeetCode] Find Duplicate Subtrees 寻找重复树

    Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne ...

随机推荐

  1. diy51单片机最小系统------从零件到51整体测试成功小白篇

    前言 因为现在网上资料很多,但是很多博主水平不一样,有很多时候,自己在网上找了很多资料,因为自己智商不够,有时候感觉很多关键性的东西没说清楚,导致解决不了问题.那现在就从一个小白的角度来记录自己做过的 ...

  2. js 关于日期,字符串转化

    <html><head><title>简单获取日期的JS</title><meta http-equiv="Content-Type&q ...

  3. CSS3美化网页元素

    <span>标签 </span>属性名 含义 举例font-family 设置字体类型 font-family:"隶书"font-size 设置字体大小 f ...

  4. DirectSound---捕获音频、Qml/C++ 集成交互

    DirectSound的音频捕获原理和播放原理差不多,内部在一个缓冲区上循环写入捕获到的数据,并且提供notify通知功能. 1. 音频捕获 因为捕获流程和播放流程类似,我们就不在这里赘述了,只给出简 ...

  5. Struts2学习笔记三 访问servlet

    结果跳转方式 转发 <!-- 转发 --> <action name="Demo1Action" class="cn.itheima.a_result. ...

  6. Leetcode 1——twosum

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  7. IQKeyboardManager使用方法

    使用方法: 将IQKeyboardManager 和 IQSegmentedNextPrevious类文件加进项目中.在AppDelegate文件中写下以下一行代码: [IQKeyBoardManag ...

  8. JAVAEE——BOS物流项目09:业务受理需求分析、创建表、实现自动分单、数据表格编辑功能使用方法和工作单快速录入

    1 学习计划 1.业务受理需求分析 n 业务通知单 n 工单 n 工作单 2.创建业务受理环节的数据表 n 业务通知单 n 工单 n 工作单 3.实现业务受理自动分单 n 在CRM服务端扩展方法根据手 ...

  9. EasyUI导航栏。

    html: <div data-options="region:'west',split:true" title="导航栏菜单" style=" ...

  10. DOM中的事件对象(event)

    在触发DOM上的某个事件时,会产生一个事件对象event,这个对象中包含着所有与事件相关的信息. 包括导致事件的元素.事件的类型以及其他与特定事件相关的信息. 例如:鼠标操作导致的事件对象中,会包含鼠 ...