![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文件夹66
from now!
展开
-
(LeetCode)102. 二叉树的层序遍历
给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。 借用了队列: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class原创 2020-06-20 15:10:36 · 105 阅读 · 0 评论 -
(LeetCode)连续子数组的最大和 求所有子数组的和的最大值
面试题42. 连续子数组的最大和 输入一个整型数组,数组里有正数也有负数。数组中的一个或连续多个整数组成一个子数组。求所有子数组的和的最大值。 要求时间复杂度为O(n)。 class Solution { public: int maxSubArray(vector<int>& nums) { vector<int> S; S.reserve(nums.size()); int pos = 0; int sum = 0; int Max = nums[0原创 2020-06-15 10:10:49 · 608 阅读 · 0 评论 -
请你找出这两个正序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。
给定两个大小为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。 请你找出这两个正序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。 你可以假设 nums1 和 nums2 不会同时为空。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/median-of-two-sorted-arrays class Solution { public: double findMedianSortedArrays(vector原创 2020-06-12 08:55:40 · 358 阅读 · 0 评论 -
(LeetCode)给定一个字符串,请你找出其中不含有重复字符的最长子串 的长度。
力扣 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 class Solution { public: int lengthOfLongestSubstring(string s) { int i = 1; int pos = 0; string sub; sub = s.substr(0); cout<<sub<<endl; int max = 0; int length = 1; if (s.size() >= 1) {原创 2020-06-11 23:07:15 · 270 阅读 · 0 评论