Skip to content

Commit

Permalink
day01 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenzhang1007 committed Jun 30, 2020
1 parent c1ab05f commit 4d08b9c
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* @lc app=leetcode.cn id=4 lang=cpp
*
* [4] 寻找两个有序数组的中位数
*
* https://leetcode-cn.com/problems/median-of-two-sorted-arrays/description/
*
* algorithms
* Hard (37.27%)
* Likes: 2822
* Dislikes: 0
* Total Accepted: 215.9K
* Total Submissions: 563.6K
* Testcase Example: '[1,3]\n[2]'
*
* 给定两个大小为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。
*
* 请你找出这两个正序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。
*
* 你可以假设 nums1 和 nums2 不会同时为空。
*
*
*
* 示例 1:
*
* nums1 = [1, 3]
* nums2 = [2]
*
* 则中位数是 2.0
*
*
* 示例 2:
*
* nums1 = [1, 2]
* nums2 = [3, 4]
*
* 则中位数是 (2 + 3)/2 = 2.5
*
*
*/

// @lc code=start
class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {

}
};
// @lc code=end

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* @lc app=leetcode.cn id=3 lang=cpp
*
* [3] 无重复字符的最长子串
*
* https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/description/
*
* algorithms
* Medium (33.71%)
* Likes: 3881
* Dislikes: 0
* Total Accepted: 542.1K
* Total Submissions: 1.6M
* Testcase Example: '"abcabcbb"'
*
* 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
*
* 示例 1:
*
* 输入: "abcabcbb"
* 输出: 3
* 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。
*
*
* 示例 2:
*
* 输入: "bbbbb"
* 输出: 1
* 解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。
*
*
* 示例 3:
*
* 输入: "pwwkew"
* 输出: 3
* 解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。
* 请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串。
*
*
*/

// @lc code=start
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map<char, int> heap;
int res = 0;
for (int i = 0, j = 0; i < s.size(); i++){
heap[s[i]]++; // 将新元素加入到哈希表中
while(heap[s[i]] > 1) // 如果有重复,必然是s[i] 重复,因为只有s[i]是新加入的
// 当s[i]的数量大于1时,将s[j]删除,并将j往后移动一位,一直删到s[i]=1
heap[s[j++]]--;
res = max(res, i-j+1);
}
return res;
}
};
// @lc code=end

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# @lc app=leetcode.cn id=3 lang=python3
#
# [3] 无重复字符的最长子串
#
# https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/description/
#
# algorithms
# Medium (33.71%)
# Likes: 3881
# Dislikes: 0
# Total Accepted: 542.1K
# Total Submissions: 1.6M
# Testcase Example: '"abcabcbb"'
#
# 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
#
# 示例 1:
#
# 输入: "abcabcbb"
# 输出: 3
# 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。
#
#
# 示例 2:
#
# 输入: "bbbbb"
# 输出: 1
# 解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。
#
#
# 示例 3:
#
# 输入: "pwwkew"
# 输出: 3
# 解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。
# 请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串。
#
#
#

# @lc code=start
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:

# @lc code=end

0 comments on commit 4d08b9c

Please sign in to comment.