原创 LeetCode:258. 各位相加
class Solution { public: int addDigits(int num) { while(num>=10) { int temp=0;
原创 LeetCode:173. 二叉搜索樹迭代器
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNo
原创 LeetCode:1492. n 的第 k 個因子
class Solution { public: int kthFactor(int n, int k) { int count=0; for(int i=1;i<=n;i++)
原创 LeetCode:1491. 去掉最低工資和最高工資後的工資平均值
class Solution { public: double average(vector<int>& salary) { sort(salary.begin(),salary.end());
原创 LeetCode:77.組合
class Solution { public: vector<vector<int>>res; //求解C(n,k),當前已經找到的組合存儲在c中,需要從start開始搜索新的元素 void genera
原创 LeetCode:168. Excel表列名稱
這個題最小的數字不是從0開始,而是從1開始。所以如果要用進制轉換的思路來解決的話,在處理每一位的時候要把當前的位進行減1操作。 class Solution { public: string convertToTitle(
原创 Leetcode:38. 外觀數列(競賽用純打表解法)
class Solution { public: string countAndSay(int n) { switch (n) { case 1: return "1"; case 2:
原创 LeetCode:307. 區域和檢索 - 數組可修改
class NumArray { public: vector<int> num; NumArray(vector<int>& nums) { num=nums; } vo
原创 LeetCode:724. 尋找數組的中心索引
分別計算某一個元素左右兩邊的元素累加和,計算完畢之後,遍歷這兩個數組的過程中,如果某一對應(i對應nums.size()-i-1,也就是數組中的任意對稱位置的下標)位置的累加和是相等的,那麼就直接返回,否則在未找到的前提下返回-1
原创 LeetCode:56. 合併區間
class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { vector<vector<int
原创 LeetCode:3. 無重複字符的最長子串
class Solution { public: int lengthOfLongestSubstring(string s) { int freq[256]={0};//初始化的時候滑動窗口中沒有任何字符
原创 LeetCode:728. 自除數
class Solution { public: bool isSelfDivided(int i) { int temp=i; while(i) {
原创 LeetCode:142. 環形鏈表 II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNo
原创 LeetCode:235. 二叉搜索樹的最近公共祖先
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNo
原创 LeetCode:441. 排列硬幣
class Solution { public: int arrangeCoins(int n) { //通過等差數列求和公式,計算出一共可能的行數,然後進行求解一元二次方程 return