Skip to content

Instantly share code, notes, and snippets.

@codertcet111
Created March 29, 2024 15:02
Show Gist options
  • Save codertcet111/da76c0ac54768bccea4d09746e2961ef to your computer and use it in GitHub Desktop.
Save codertcet111/da76c0ac54768bccea4d09746e2961ef to your computer and use it in GitHub Desktop.
Leetcode 8: String to integer atoi
Leetcode 8: String to integer atoi
# @param {String} s
# @return {Integer}
def my_atoi(s)
return nil if s == nil
r_n = s.gsub(/[^0-9-]/, "").to_i
max_n = (1 << 31) - 1
r_n > max_n || r_n < (max_n * -1) ? 0 : r_n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment