码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode:用HashMap解决问题

时间:2018-01-28 15:32:07      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:col   gpo   new   get   log   解决问题   lock   div   nbsp   

LeetCode:用HashMap解决问题

Find Anagram Mappings

 1 class Solution {
 2     public int[] anagramMappings(int[] A, int[] B) {
 3         Map<Integer, Integer> D = new HashMap();
 4         for (int i = 0; i < B.length; ++i)
 5             D.put(B[i], i);
 6 
 7         int[] ans = new int[A.length];
 8         int t = 0;
 9         for (int x: A)
10             ans[t++] = D.get(x);
11         return ans;
12     }
13 }

思考:用字典来解决问题,巧妙将数组编号转换为页码,然后快速查表

 

LeetCode:用HashMap解决问题

标签:col   gpo   new   get   log   解决问题   lock   div   nbsp   

原文地址:https://www.cnblogs.com/MrSaver/p/8371180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!