Skip to content

Longest Palindrome#36

Closed
rihib wants to merge 288 commits intomainfrom
longest_palindrome
Closed

Longest Palindrome#36
rihib wants to merge 288 commits intomainfrom
longest_palindrome

Conversation

@rihib
Copy link
Owner

@rihib rihib commented Sep 18, 2024

Longest Palindromeを解きました。レビューをお願いいたします。

問題:https://leetcode.com/problems/longest-palindrome/
言語:Go

既に解いた方々:
NobukiFukui/Grind75-ProgrammingTraining#31
Kitaken0107/GrindEasy#27

Copy link

@usatie usatie left a comment

Choose a reason for hiding this comment

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

良いと思います!nitコメントでしかないですが、つけておきました。個人的には二周した方が好きです。このくらいで面倒臭いですかね・・・?

*/
func longestPalindrome(s string) int {
length := 0
frequencies := make(map[rune]int, len(s))
Copy link

Choose a reason for hiding this comment

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

keyが存在しないか1かしかないので、frequenciesという名前が正しくはないような気もします。
frequenciesという名前なら1週目はカウントだけしてほしいかも。

Choose a reason for hiding this comment

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

同じ感覚があります

*/
func longestPalindrome(s string) int {
length := 0
frequencies := make(map[rune]int, len(s))

Choose a reason for hiding this comment

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

同じ感覚があります

/*
時間:6分

1周目はカウントだけして、2周目にlengthを求めるという方法も取れると思うが、for文を2つ書くのがめんどくさかった(計算量的にはどちらも大差ないと思う)ので1周で収めるようにした。

Choose a reason for hiding this comment

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

1周目はカウントだけして、2周目にlengthを求めるという方法も取れると思う

これが一番自然な方法な気がしていて、
これに言及した上で別の観点で他の方法を選択しているのが良いと思いました。

Copy link

Choose a reason for hiding this comment

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

私は1周目で単にカウントして2周目で計算するでしょう。そのほうが読みやすいと思うので。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants