Блог пользователя vatayush

Автор vatayush, 9 лет назад, По-английски

hi!i was solving this problem.it's strange that this submission1 got TLE while when i used set instead of visited array to keep track of colors the same code got AC.My AC code.Can someone please explain me why??

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Each time when you create an array it takes O(size) time. So your algorithm in worst case will create 100000 elements array 100000 times what is too much. If you create set it is empty so it takes O(1) time and O(log n) for each operation.