-
Notifications
You must be signed in to change notification settings - Fork 0
8. String to Integer (atoi) #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| - 数値を読んでいく | ||
|
|
||
| INT_MAX, INT_MINを超えたらそこで終了する。Pythonのintは理論上は上限がないので途中のオーバーフローなどは考えなくて良い。 | ||
| CやC++で実装する場合でも32bitより大きい型(long)を確保してあげれば考えなくて良くなる。← ただlongの場合のオーバーフローの考慮などどこかではちゃんと考慮しないといけない。その場合は、桁上りの計算をする前にオーバーフローするかどうかを判定すれば良い。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long はデータモデルによってサイズが異なります。
https://ja.wikipedia.org/wiki/64%E3%83%93%E3%83%83%E3%83%88
LP64 LLP64 等でお調べください。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます。C++の規格では各typeの最小のbit数を規程していて、実際のサイズはその制約を満たす上で選択されたデータモデルによって決まるんですね。
C++の規格ではlongの最小サイズは32bitとして決められていて、LP32のようなデータモデルだと32bitになる。long long型については64bit以上であることが仕様上保証されている。
| index += 1 | ||
| return index | ||
|
|
||
| def get_sign(begin): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文字を解析してインデックスと符号を得ているため、 get より parse という単語を使用したほうがしっくりくると思います。
https://leetcode.com/problems/string-to-integer-atoi