成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

[LeetCode] 760. Find Anagram Mappings

caozhijian / 1690人閱讀

Problem

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].

Solution
class Solution {
    public int[] anagramMappings(int[] A, int[] B) {
        Map map = new HashMap<>();
        for (int i = 0; i < B.length; i++) {
            map.put(B[i], i);
        }
        for (int i = 0; i < A.length; i++) {
            A[i] = map.get(A[i]);
        }
        return A;
    }
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/72319.html

相關(guān)文章

  • [LeetCode] 438. Find All Anagrams in a String [滑動(dòng)窗

    Problem Given a string s and a non-empty string p, find all the start indices of ps anagrams in s. Strings consists of lowercase English letters only and the length of both strings s and p will not be...

    muzhuyu 評(píng)論0 收藏0
  • [LeetCode]Find All Anagrams in a String

    摘要:解題思路,就是只順序不同但個(gè)數(shù)相同的字符串,那我們就可以利用的思想來比較每個(gè)字符串中字符出現(xiàn)的個(gè)數(shù)是否相等。 Find All Anagrams in a StringGiven a string s and a non-empty string p, find all the start indices of ps anagrams in s. Strings consists of...

    niceforbear 評(píng)論0 收藏0
  • leetcode438. Find All Anagrams in a String

    摘要:題目要求思路和代碼這是一個(gè)簡(jiǎn)單的雙指針問題,即左指針指向可以作為起點(diǎn)的子數(shù)組下標(biāo),右指針則不停向右移動(dòng),將更多的元素囊括進(jìn)來,從而確保該左右指針內(nèi)的元素是目標(biāo)數(shù)組的一個(gè)兄弟子數(shù)組即每個(gè)字母的個(gè)數(shù)均相等左指針記錄每個(gè)字母出現(xiàn)的次數(shù)拷貝一個(gè) 題目要求 Given a string s and a non-empty string p, find all the start indices ...

    wangbinke 評(píng)論0 收藏0
  • [LeetCode] Group Anagram

    Problem Given an array of strings, group anagrams together. Example: Input: [eat, tea, tan, ate, nat, bat], Output: [ [ate,eat,tea], [nat,tan], [bat] ] Note: All inputs will be in lowercase.The ...

    kid143 評(píng)論0 收藏0
  • [Leetcode] Valid Anagram 驗(yàn)證變形詞

    摘要:排序法復(fù)雜度時(shí)間空間思路因?yàn)樽冃卧~兩個(gè)單詞對(duì)應(yīng)字母出現(xiàn)的次數(shù)都相同,所以如果將兩個(gè)單詞按字母順序排序,肯定會(huì)變?yōu)橐粋€(gè)字符串,如果字符串不相同,則不是變形詞。 Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = a...

    justjavac 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<