
LeetCode
yyiloveuu
这个作者很懒,什么都没留下…
展开
-
4. 寻找两个正序数组的中位数【leetcode】
先发一个暴力版 class Solution { public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { int m = nums1.size(), n = nums2.size(); int k = 0, i = 0, j = 0; vector<int> arr(m + n, 0);原创 2022-02-24 00:30:16 · 80 阅读 · 0 评论 -
3. 无重复字符的最长子串【leetcode】
记录自己刷题 class Solution { public: int lengthOfLongestSubstring(string s) { // 如果长度为0, 直接返回最后的结果 if (s.size() == 0) return 0; // set存滑动窗口 unordered_set<char> window; // 左边定义0开始 int left = 0, n = s.siz原创 2022-02-23 00:48:30 · 77 阅读 · 0 评论 -
2. 两数相加【leetcode】
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next.原创 2022-02-23 00:27:36 · 519 阅读 · 0 评论 -
1. 两数之和【leetcode】
记录自己刷题的日子。。。 class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { // 1、暴力枚举 int n = nums.size(); for (int i = 0; i < n; i ++) { for (int j = i+1; j < n; j++)原创 2022-02-22 23:47:43 · 148 阅读 · 0 评论 -
LeetCode 1512. 好数对的数目
第一种方法,暴力枚举 def numIdenticalPairs(self, nums: List[int]) -> int: # 暴力枚举 sum = 0 for i in range(0, len(nums)): for j in range(i+1, len(nums)): if nums[i] == nums[j]: sum = sum .原创 2020-09-29 15:44:25 · 238 阅读 · 0 评论