原创 LeetCode 0367 Valid Perfect Square【驗證完美平方數】
Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do n
原创 PAT A1019 General Palindromic Number(20)【普通迴文數,進位制】
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For examp
原创 LeetCode 0383 Ransom Note【贖金信,哈希】
題目鏈接 383. Ransom Note | Given an arbitrary ransom note string and another string containing letters from all th
原创 LeetCode 0771 Jewels and Stones【寶石與石頭,哈希】
題目鏈接 771. Jewels and Stones | You’re given strings J representing the types of stones that are jewels, and S re
原创 LeetCode 0278 First Bad Version【第一個錯誤的版本,二分】
題目鏈接 278.First Bad Version | You are a product manager and currently leading a team to develop a new product. U
原创 LeetCode 1232 Check If It Is a Straight Line【 綴點成線,數學】
題目鏈接 1232. Check If It Is a Straight Line | 1232. 綴點成線 You are given an array coordinates, coordinates[i] = [x,
原创 7-2 三階幸福數 (20分)
對一個十進制數的各位數字做一次立方和,稱作一次迭代。如果一個十進制數能通過 h 次迭代得到 1,就稱該數爲三階幸福數,迭代的次數 h 稱爲幸福度。例如 1579 經過 1 次迭代得到 1198,2 次迭代後得到 1243,3 次迭
原创 7-1 Knuth洗牌法 (20分)
Knuth 洗牌法是生成 { 1, 2, …, n } 的一個隨機重排列的算法。與每次反覆隨機生成一個數字,直到獲得一個不重複的新數字的算法不同,Knuth 洗牌法從原始序列 { 1, 2, …, n } 開始,逐次洗牌。洗牌的方
原创 7-3 垃圾分類 (20分)
據香港《南華早報》2019年7月15日文章,上海嚴格的垃圾分類新規令不少居民抓狂。這催生出大量幫助找出正確分類答案的App和小程序。目前僅微信上就至少有280種與垃圾處理有關的App,在蘋果應用商店也達130種。支付寶表示,已有6
原创 LeetCode 0117 Populating Next Right Pointers in Each Node II【二叉樹,BFS】
Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next point
原创 LeetCode 0111 Minimum Depth of Binary Tree【二叉樹,最小深度,遞歸】
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from
原创 LeetCode 0589 N-ary Tree Preorder Traversal【N叉樹,DFS】
Given an n-ary tree, return the preorder traversal of its nodes’ values. Nary-Tree input serialization is represent
原创 LeetCode 0404 Sum of Left Leaves【左邊葉節點數量,二叉樹,遞歸】
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are
原创 LeetCode 0703 Kth Largest Element in a Stream【優先隊列,堆】
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted o
原创 LeetCode 0104 Maximum Depth of Binary Tree 【二叉樹】
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from t