deno.land / x / masx200_leetcode_test@10.6.5 / minimum-index-sum-of-two-lists / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export default function findRestaurant( list1: string[], list2: string[],): string[] { const RestaurantToIndex1 = new Map( Array.from(list1.entries()).map(([index, restaurant]) => [ restaurant, index, ]), ); const RestaurantToIndex2 = new Map( Array.from(list2.entries()).map(([index, restaurant]) => [ restaurant, index, ]), ); const commonRestaurants = list1.filter((restaurant) => RestaurantToIndex2.has(restaurant) ); const RestaurantsCommonToIndexSum = commonRestaurants.map( (restaurant) => [ restaurant, (RestaurantToIndex1.get(restaurant) ?? 0) + (RestaurantToIndex2.get(restaurant) ?? 0), ] as const, );
const minimumIndexSum = Math.min( ...RestaurantsCommonToIndexSum.map((a) => a[1]), ); return RestaurantsCommonToIndexSum.filter( (a) => a[1] === minimumIndexSum, ).map((a) => a[0]);}
masx200_leetcode_test

Version Info

Tagged at
a year ago