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

First submission #117

Merged
merged 1 commit into from
Jan 3, 2017
Merged

First submission #117

merged 1 commit into from
Jan 3, 2017

Conversation

erocs
Copy link
Collaborator

@erocs erocs commented Jan 3, 2017

No description provided.

Copy link
Contributor

@MJUIUC MJUIUC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I don't know go so I can't comment on your code. You should ask someone in one of the channels if they know it so that you can get a review 👍

@Remillardj
Copy link
Contributor

Remillardj commented Jan 3, 2017

  • Code review
  • Correct path
  • Code tested
  • Check for conflicts
  • Merge PR

Copy link
Contributor

@Remillardj Remillardj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review:

Its minor, but Im not sure why you make your imports multi-line capable when all you need is "fmt". This just can make your code cluttered.

In challenge_2, you make variables singles and repeats. Why? If all you're looking for is unique character or number, why stash the repeated and delete a character or number from singles? Surely there is a better way to do this. Ill go ahead and merge your PR since we lack a lot of Go submissions.

But good job with everything else! I like your style os code and your use of Go!

@Remillardj Remillardj merged commit a780525 into YearOfProgramming:master Jan 3, 2017

func FindSingleton(int_array []int) (found int) {
singles := make(map[int]int)
repeats := make(map[int]int)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you can't just have one map of map[int]int and just loop over it at the end to find the (or a) single and return that? One less map allocation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one less loop iteration at the cost of one allocation. Different trade-offs. Realistically, these maps are being used as Sets and repeats doesn't need to bother counting.

}
}
for k, _ := range singles {
found = k
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well exit the for loop when you find one since you'll just be reassigning found each time you find one and it doesn't look like it matters what one you return.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I had the return within the loop, I would still need the end the function return, since the loop might contain nothing. It doesn't gain anything since this loop should only iterate one value, per spec. If I updated to have both return statements, I would also change the return value to (int, error) and rework the loop so an error could be returned on no single or multiple singles. Not adding the error return was just my laziness. ;)

"fmt"
)

func FindMajority(int_array []int) int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go idioms is to use smaller naming conventions. This is also a slice, not an array. Maybe ints

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ints would be good as it is still descriptive enough.

}

func (t *TreeNode) String() string {
l := ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd more typically see

var l string
var r string

You could do the same for the numbers as above but it's mainly in strings where it's a bit odd to use shorthand to create an empty value string when it's already that way with var

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either works fine. I find explicit initialization to be more descriptive but each to his own.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also yes I do appreciate the irony of 1-letter variable names when talking about descriptiveness. Once again, laziness in my part to crank out a simple problem, lol. I'm glad code standards will be implemented in the repo.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants