leetcode刷题记录--Find Anagram Mappings

题目

难度:easy

Given two lists Aand B, and B is an anagram of A. B 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 A appears at B[4], and so on.
Note:

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

第一次解法

/**
 * @param {number[]} A
 * @param {number[]} B
 * @return {number[]}
 */
var anagramMappings = function(A, B) {
    let res = []
    A.forEach(function(item){
        res.push(B.indexOf(item))
    })
    return res
};
# runtime : 94 ms
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,034评论 0 23
  • “咚咚咚!”离雨有礼貌的敲了敲门,“进来!” “校长,我和我妹妹在哪个班?”离雨把两份转入通知书递给校长,校长看了...
    波多黎各阅读 209评论 0 1
  • Low Poly火了很久,今儿要说的却是在低面化之后更近一步的风格化还能怎样玩?想不到的,想到的,都在文里里,喜欢...
    阿随向前冲阅读 6,087评论 72 194
  • 1.TP5.0的安装 a) 源代码包安装 1、去thinkphp官网(www.thinkphp.cn) 下载 完整...
    沈九壹阅读 2,202评论 0 0
  • 突然好像去海边走走,去看看蓝色天空,去闻闻海水的味道。 这是某天晚上在床上睡不早的时候,产生的一些想法,夹着着内心...
    爱吃巧克力的泡芙阅读 190评论 0 1