Contents

[Leetcode Pattern] - Array, String

Array, String

Preface

Array and string topic can usually treated as the similar topic, so today we are going to learn the most common design pattern for those two topics.

Two pointer

Introduction

  • Using two different pointer to frame out the current processing array while traversing the array

When to use?

  • Implement the various size sliding window

  • Kadane’s Algorithm: Iterative dynamic programming algorithm

Sliding Window

Introduction

  • A range of frame to traverse the array

When to use?

  • Check for the count of the unique element contains in the frame

Sorted Array

Introduction

  • Sort the array to the ascending/descending order.

When to use?

  • If the problem has stated that the array is sorted, you might have to consider whether there isn’t there binary search method or while traversing the array, you can optimize the scanning time by skipping the duplicated value.