Re: [閒聊] 每日leetcode

作者: Rushia (みけねこ的鼻屎)   2024-03-13 09:26:34
https://leetcode.com/problems/find-the-pivot-integer
2485. Find the Pivot Integer
給定一個數字n,找出一個介於1~n的數字k滿足 1+2+...+k = k+(k+1)+(k+2)+...+n,如
果不存在返回-1。
思路:
1.先求1~n的和
2.再遍歷一次1~n把pivot放進去判斷
pycode:
作者: NTUEE2CS (EE轉CS)   2024-03-13 09:29:00
大師
作者: JIWP (JIWP)   2024-03-13 09:34:00
大師
作者: sustainer123 (caster)   2024-03-13 09:55:00
大師 我只想到第一種解法

Links booklink

Contact Us: admin [ a t ] ucptt.com