633. Sum of Square Numbers

餘生
Aug 26, 2021

--

Runtime: 4 ms, faster than 54.23% of others
Memory Usage: 6 MB, less than 26.87% of others

不用兩個迴圈去找a跟b,將a²移到右邊後判斷一下就可以下降到O(n),但看起來似乎有更快或更節省記憶空間的方法。而迴圈條件式不寫成c≥a²是因為a=46341會overflow,但用long的話有可能會增加Memory Usage。這裡不適合用強轉型態的方式做判斷b_float==(int)b_float,雖然大部分的case都可以過,但還是會遇到b_float遺失的精確度剛好等於(int)b_float,造成答案不一樣。

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

餘生
餘生

Written by 餘生

0 Followers

正在北大當菸酒生

No responses yet

Write a response