Byte Pattern Search
A file can be represented as a list of bytes, and sometimes you need to find a smaller byte fragment inside it. Given data and pattern, return the index where pattern first appears as a contiguous part of data. If the pattern is not found, return -1. An empty pattern is considered found at index 0.
Примеры
Ввод
[1, 2, 3, 4, 5], [3, 4]Вывод
2Ввод
[1, 2, 3], [4]Вывод
-1Ввод
[5, 5, 5, 5], [5, 5]Вывод
0Нужно реализовать
def find_byte_pattern(data, pattern):
Теги
stringstwo-pointershashmap
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteachVisible tests
1
Input
[1,2,3,4,5], [3,4]Expected
22
Input
[1,2,3], [4]Expected
-13
Input
[5,5,5,5], [5,5]Expected
04
Input
[1,2,3], []Expected
05
Input
[1,2,1,2,3], [1,2,3]Expected
26
Input
[], [1]Expected
-1Focus radio
Paused · SomaFM · Fluid