Skip to content

Leetocde Pattern

Published: at 08:00 AM

Table of contents

Open Table of contents

Preface

I’ll conclude some common patterns of LC, which includes the identifying symbol and important ideas of using. Sometimes, I feel I could identify the pattern but can’t work with the pattern. Update:

slide window & two pointers

slide window

It always be used in the array or string, especially when we need to find the subarray or substring. We can use 2 pointers to control the length of window to find the best case.

2 pointers

It always be used in the ordered array or string, linkedlist, to find a special case.

compare

linked list

edge condition

when you are required to return a new list that is the result of some operation like merging, inserting, or sorting.

Without a dummy head, you would have to write additional conditional statements to handle the initialization of the head of the result list. This is because the first element requires special handling:

Others