Linked List Worked Example: Leetcode 160 Intersection of Two Linked Lists

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Hey :) Just letting you know, that you are an inspiration for me to do at least one leetcode every day :)

JanKowalski-iosr
Автор

great improvement! glad to see you crushing these now and doing it quicker!

perotin
Автор

Ok so about the TLE, this is part of the difficulty of leetcode, you only pass if your algorithm is efficient enough.
You can gain insight as to how efficient your algorithm has to be by looking at the constraints, here it says that the length of listA and listB is less than 3*1e4.
This means that len(listA)*len(listB) which your first algorithm was, is just barely not fast enough.
When you submit it and not everything is correct, it will (usually, not sure if its allways) the smallest testcase you failed. You can also see how many of the tests you passed (36 out of 39),
so when you get a TLE it almost always means that your algorithm is correct, but not fast enough (otherwise it would've failed a shorter test with a wrong value).

raksop.
welcome to shbcf.ru