C++一行解Leetcode 326 Power of Three
利用3的羃次方的因數也是3的羃次方,導出一行C++程式碼
[解答請進]
[codes on Leetcode]https://leetcode.com/problems/power-of-three/solutions/7073196/easy-n-n-0-vs-1-liner-beats-100/
[Numbery theory & Primes Playlist]https://www.youtube.com/watch?v=3FUyGjH_FZ0&list=PLYRlUBnWnd5Ld53SovfXQROVMAI_La2dv
class Solution { public: // use p=3 being prime static bool isPowerOfThree(int n) { return n>0 and 1162261467%n==0; } };
沒有留言:
張貼留言
HTML 編輯器