Skip to content
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

Solve LeetCode problem [P7] #19

Open
salastro opened this issue Mar 8, 2022 · 0 comments
Open

Solve LeetCode problem [P7] #19

salastro opened this issue Mar 8, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@salastro
Copy link
Contributor

salastro commented Mar 8, 2022

I would like to request to see the following problem solved:

My proposed solution(s):

I was not able to think of a straightforward solution that works on negative integers. Probably my solution for problem no. 2 (#11) affected my thinking in a negative way.

 arrToInt needs to start at index zero since the use of 10*0 in units
⎕IO0

 the range in which acceptable values exist
range  (¯2*31) (1-2*31)

 if in range return the number, zero otherwise
inRange  {×/range<}

 convert an array of single-digit integers into an integer in reverse (does
 not work if negative)
arrToInt  {+/×10*}

 convert the integer into an array (does not work if negative) reverse it into
 an integer then check if in range
Sol  { inRange arrToInt ¨  }

EDIT:-
I do not know how, but I didn't think of operating on the absolute value and then multiplying the result by the sign.

Sol  { (×) × inRange arrToInt ¨ | }
@salastro salastro added the enhancement New feature or request label Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant