forked from YearOfProgramming/2017Challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Takes a list of sorted values and squares them, resorting | ||
the resulting list. The algorithm cannot use sort on the | ||
resulting list. | ||
|
||
If the first element of the list is greater then 0, we can | ||
just return the list squared as tis already sorted. | ||
|
||
Otherwise, we work backwards, but comparing the absolute value | ||
of the first element with the last element and squaring the largest. | ||
|
||
We then return the reverse of the squared list to get it sorted from | ||
smallest to largest. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters