
LeetCode
CCSUZB
吾生也有涯,而知也无涯
展开
-
LeetCode-617:合并二叉树
递归解法class Solution {public: TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) { if(t1 == NULL) return t2; if(t2 == NULL) return t1; TreeNode *res =...原创 2019-09-09 20:33:05 · 107 阅读 · 0 评论 -
LeetCode-1:两数之和
使用map减小时间复杂度class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int,int> record; for(int i=0;i<nums.size();i++){...原创 2019-09-09 20:32:36 · 157 阅读 · 0 评论 -
LeetCode-581:最短无需连续子数组
将数组进行排序后与未排序之前的数组从头开始对比得到第一个不相同数的索引index_1,从尾开始对比得到第一个不相同数的索引index_2,所求的结果即为index_2-index_1+1class Solution {public: int findUnsortedSubarray(vector<int>& nums) { vector<...原创 2019-09-09 20:32:50 · 245 阅读 · 0 评论