Re: [閒聊] 每日leetcode已回收

看板Marginalman作者 (虛構史學家)時間1年前 (2024/06/17 13:52), 編輯推噓2(200)
留言2則, 2人參與, 1年前最新討論串374/1548 (看更多)
※ 引述《sustainer123 (caster )》之銘言: : https://leetcode.com/problems/sum-of-square-numbers : 633. Sum of Square Numbers : 給定一非負整數C 請回傳是否存在a,b兩數使得a**2 + b**2 == c : 思路: : two pointer 一樣雙指標 要轉成i64不然會不夠用 Code: impl Solution { pub fn judge_square_sum(c: i32) -> bool { let c_i64 = c as i64; let c_sqrt = (c as f64).sqrt() as i64; let mut a: i64 = 0; let mut b: i64 = c_sqrt; while a <= b { let square = a * a + b * b; if square == c_i64 { return true; } else if square < c_i64 { a += 1; } else if square > c_i64 { b -= 1; } } false } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.32.48.170 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1718603524.A.7E4.html

06/17 13:56, 1年前 , 1F
拜託你別捲了
06/17 13:56, 1F

06/17 13:59, 1年前 , 2F
大師
06/17 13:59, 2F
文章代碼(AID): #1cRyy4Va (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cRyy4Va (Marginalman)