摘要: 1601. 最多可达成的换楼请求数目 解题思路:由于数据不超过20,所以二进制枚举是可行的 class Solution { public: int maximumRequests(int n, vector<vector<int>>& requests) { int ans=0; int flag 阅读全文
posted @ 2022-02-28 23:12 夜灯长明 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 102. 二叉树的层序遍历 思路:简单BFS即可 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : v 阅读全文
posted @ 2022-02-27 22:53 夜灯长明 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 553. 最优除法 思路:因为要x1/x2/x3/...../xn最大,可以看成x/y,当x仅仅为x1时,x最大 class Solution { public: string optimalDivision(vector<int>& nums) { int len=nums.size(); str 阅读全文
posted @ 2022-02-27 22:28 夜灯长明 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 94. 二叉树的中序遍历 递归法 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), l 阅读全文
posted @ 2022-02-27 22:20 夜灯长明 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 树的定义 树是n(n>=0)个结点的有限集。n=0时称为空树。在任意一颗非空树中: 1.有且仅有一个特定的称为根(Root)的结点 2.当n>1时,其余结点可分为m(m>0)个互不相交的有限集T1,T2,...,Tm,其中每一个集合本身又是一颗树,并且称为根的子树 结点的分类 树的结点包含一个数据元 阅读全文
posted @ 2022-02-27 21:56 夜灯长明 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 题目链接 解题思路:简单模拟 class Solution { public: string convert(string s, int numRows) { if(numRows==1){ return s; } int L=(numRows-1)*2; int R=0; int len=s.si 阅读全文
posted @ 2022-01-25 18:52 夜灯长明 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 题目链接 解题思路:简单模拟即可 class Solution { public: int numberOfMatches(int n) { int sum=0; while(n!=1){ if(n%2==0){ n=n>>1; sum+=n; } else{ n=n>>1; sum+=n; n++ 阅读全文
posted @ 2022-01-25 18:02 夜灯长明 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 题目链接 动态规划 class Solution { public: string longestPalindrome(string s) { int begin=0; int n=s.size(); int Max=1; vector<vector<int>>dp(n,vector<int>(n) 阅读全文
posted @ 2022-01-25 17:53 夜灯长明 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 参考博客 该算法可以在时间空间都为O(n),求出最大的回文子串 string longestPalindrome(string s) { string str; string ans; int start=0, end=0; str += "$#"; for (int i = 0; i < s.si 阅读全文
posted @ 2022-01-25 17:45 夜灯长明 阅读(23) 评论(0) 推荐(0) 编辑
摘要: string的初始化 string str1 = "hello world"; // str1 = "hello world" string str2("hello world"); // str2 = "hello world" string str3 = str1; // str3 = "hel 阅读全文
posted @ 2022-01-24 17:57 夜灯长明 阅读(65) 评论(0) 推荐(0) 编辑