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 3 years have passed since last update.

配列を回転させる

Posted at

問題

要素がn個の配列を左方向にi要素分回転させる

例)012345 を 3つずらして 345012 にする

n: 6
i: 3

処理前 |0|1|2|3|4|5|
処理後 |3|4|5|0|1|2|

考え方

# 定義
a : 0〜i要素分(012)
b : 残り(345)
a': aの逆転(210)
b': bの逆転(543)


# 流れ
1. ab     : 012345
2. a'b    : 210345 // reverse(0, i-1)
3. a'b'   : 210543 // reverse(i, n-1) 
4. (a'b')': 345012 // reverse(0, n-1)

参考書籍

珠玉のプログラミング 本質を見抜いたアルゴリズムとデータ構造
https://amzn.to/3N5mMTI

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?