最长不重复字符子串
最长不重复字符子串
ACWing: 61.最长不含重复字符的子字符串
LeetCode: 3.无重复字符的最长子串
1234567891011121314151617181920class Solution {public: int lengthOfLongestSubstring(string s) { int ans = 0; std::unordered_map<char, int> hash; for (int i = 0, j = 0; j < s.size(); ++j) { hash[s[j]]++; while (hash[s[j]] > 1) { // i不断前进,直到到了重复字符第一次出现的地方 hash[s[i]]--; i++; } ans = std::max(an ...
求两线段的交点
求两个线段的交点
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273#include <iostream>struct Point { double x; double y;};bool is_intersection(Point A, Point B, Point C, Point D) { // 计算向量 AB 和 AC 的叉积 double c1 = (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x); // 计算向量 AB 和 AD 的叉积 double c2 = (B.x - A.x) * (D.y - A.y) - (B.y - A.y) * (D.x - A.x); // 计算向量 CD 和 CA 的叉积 double c3 = (D.x ...

