[抄题]:

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

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

先存原数组,不好读取

[一句话思路]:

先存新数组,别开生面

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

先存新数组,别开生面

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

class Solution {
public int[] anagramMappings(int[] A, int[] B) {
//ini map
int l = A.length;
int[] res = new int[l];
HashMap<Integer, Integer> map = new HashMap<>(); //cc
if (A.length == 0 && B.length == 0) {
return res;
} //for, put b, find a
for (int i = 0; i < l; i++) {
map.put(B[i], i);
}
for (int i = 0; i < l; i++) {
res[i] = map.get(A[i]);
} //return
return res;
}
}

760. Find Anagram Mappings乱序字符串的坐标位置的更多相关文章

  1. lintcode:anagrams 乱序字符串

    题目 乱序字符串 给出一个字符串数组S,找到其中所有的乱序字符串(Anagram).如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中. 您在真实的面试中是否遇到过这个 ...

  2. Lintcode--003(乱序字符串)

    给出一个字符串数组S,找到其中所有的乱序字符串(Anagram).如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中. 注意事项 所有的字符串都只包含小写字母   样例 ...

  3. 乱序字符串anagrams

    [抄题]: 给出一个字符串数组S,找到其中所有的乱序字符串(Anagram).如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中. 对于字符串数组 ["lin ...

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

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

  5. LeetCode 760. Find Anagram Mappings

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

  6. 760. Find Anagram Mappings

    Given two lists Aand B, and B is an anagram of A. B is an anagram of A means B is made by randomizin ...

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

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

  8. LintCode-乱序字符串

    题目描述: 给出一个字符串数组S,找到其中所有的乱序字符串(Anagram).如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中. 注意事项 所有的字符串都只包含小写字 ...

  9. lintcode-171-乱序字符串

    171-乱序字符串 给出一个字符串数组S,找到其中所有的乱序字符串(Anagram).如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中. 注意事项 所有的字符串都只包 ...

随机推荐

  1. java之 Timer 类的简单使用案例

              (如果您看到本文章务必看结尾!) 第一次用Timer类,记录一下个人理解. 场景:做苹果内容结果验证时,根据苹果支付凭证去苹果官方服务器验证是否支付成功.但因为苹果服务器比较慢,第 ...

  2. SQLSERVER XML 类型列的模糊查询

    select <column_name> from MyTable where <column_name>.value('(/root/sub-tag)[1]', 'varch ...

  3. canvas基础学习(三)

    一.图片加载控件 在canvas效果制作中常常要使用多张图片,为了提高用户体验,需要给用户提供一个图片加载中的过度页面效果.过度效果,我在项目中使用的是Sonic.js,它在git上的地址为https ...

  4. Jmeter基本组件

    学习jmeter首先配置环境,使工具运行起来,然后需要了解该工具大致的内容,以下是写的Jmeter基本组件 1.添加线程组:右键点击“测试计划”-->“添加”-->“Threads(Use ...

  5. python 类的定义和继承

    python 2 中类 一.类定义: ? 1 2 class <类名>:   <语句> 类实例化后,可以使用其属性,实际上,创建一个类之后,可以通过类名访问其属性如果直接使用类 ...

  6. linux查询组与用户getent

    getent group zabbix getent passwd zabbix getent group zabbix > /dev/null || groupadd -r zabbixget ...

  7. swing之flowlayout

    import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; //1.继承 JFrame类 // ...

  8. 控制input框输入非数字

    <input type="text" onkeyup="value=value.replace(/[^\d.]/g,'')">

  9. 在.net中读写config文件的各种方法(自定义config节点)

    http://www.cnblogs.com/fish-li/archive/2011/12/18/2292037.html 阅读目录 开始 config文件 - 自定义配置节点 config文件 - ...

  10. 试用 Eagle 9.1

    试用 Eagle 9.1 有推挤功能 原理图可以设置组装变体. 输出的 CAM 可以自定义,没有 Protel 那么死板. 保存的文件是 xml 文件,可以自由解析.