Skip to content

Latest commit

 

History

History
59 lines (34 loc) · 1.19 KB

File metadata and controls

59 lines (34 loc) · 1.19 KB

中文文档

Description

You are given two arrays, one shorter (with all distinct elements) and one longer. Find the shortest subarray in the longer array that contains all the elements in the shorter array. The items can appear in any order.

Return the indexes of the leftmost and the rightmost elements of the array. If there are more than one answer, return the one that has the smallest left index. If there is no answer, return an empty array.

Example 1:

Input:

big = [7,5,9,0,2,1,3,5,7,9,1,1,5,8,8,9,7]

small = [1,5,9]

Output: [7,10]

Example 2:

Input:

big = [1,2,3]

small = [4]

Output: []

Note:

  • big.length <= 100000
  • 1 <= small.length <= 100000

Solutions

Python3

Java

...