0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LeetCode ::: 26 /// Remove Duplicates from Sorted Array

Last updated at Posted at 2019-10-15

:lemon: :pear: 思考回路

「Two Pointer」というアプローチを使ってみました。

  • まず、配列の長さが 0 だったら、もう用がないので、リターンします。
  • 変数 i を用意し、ポインタ①号として 0 を代入しておきます。
  • インプットの配列をループします。
  • 通常 for ループの中だけで使う変数 j はポインタ②号で 1 を代入。
  • で、ポインタ①号とポインタ②号、それぞれ指した配列のアイテムを比較します。
  • もし二つのアイテムが違ったら、i が指したアイテムを j が指したアイテムに置き換えて、i 足す 1 で次のループへ移行します。
  • 最後の i + 1 は実際にユニークなアイテムの数量です。

See the Pen LeetCode ::: 26 /// Remove Duplicates from Sorted Array by jujuriri (@jujuriri) on CodePen.

--- :apple: :green_apple: `参考したサイト、助かりました` [Tackling Algorithms: Counting Unique Values](https://dev.to/denisepen/tackling-algorithms-counting-unique-values-1a5n)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?