Skip to content

Commit

Permalink
add: papers and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
binacs committed Jun 1, 2024
1 parent 2a39e89 commit 49620ab
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 25 deletions.
38 changes: 20 additions & 18 deletions basic/binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,26 +448,28 @@ class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
int n1 = nums1.size(), n2 = nums2.size();
if (n1 > n2) return findMedianSortedArrays(nums2, nums1);
// l 是 nums1 中划分点的右边界 取值范围 [0, n1]
// 对应:l 左侧的值为 [空, n1-1]
// 也即:l 左侧的值 <= 中点值
if (n1 > n2)
return findMedianSortedArrays(nums2, nums1);

// 找到一个左半边的结束位置, 使得两边有严格大小关系
int l = 0, r = n1;
// 找到第一个大于等于 lv2 的位置 l
while (l < r) {
// 左侧有 i 个 总共应有(n1+n2)/2个
int i = l + (r - l) / 2;
// nums2 右边界 因为n1和n2大小关系 j永远不会取0(除非n1=n2)
int j = (n1 + n2) / 2 - i;
if (nums1[i] < nums2[j-1]) l = i + 1; // rv1 和 lv2 对比 nums1 选的太少
else r = i;
}
int i = l, j = (n1 + n2) / 2 - i;
int lv1 = i ? nums1[i - 1] : INT_MIN;
int rv1 = i < n1 ? nums1[i] : INT_MAX;
int lv2 = j ? nums2[j - 1] : INT_MIN;
int rv2 = j < n2 ? nums2[j] : INT_MAX;
if((n1 + n2) & 1) return min(rv1, rv2);
int mid = l + (r - l) / 2;
int l1 = mid;
int l2 = (n1 + n2) / 2 - l1;
if (nums1[l1] < nums2[l2 - 1]) // ATTENTION 个数 -> 下标 偏移
l = mid + 1;
else
r = mid;
}

int l1 = l, l2 = (n1 + n2) / 2 - l1;
int lv1 = l1 ? nums1[l1 - 1] : INT_MIN;
int rv1 = l1 < n1 ? nums1[l1] : INT_MAX;
int lv2 = l2 ? nums2[l2 - 1] : INT_MIN;
int rv2 = l2 < n2 ? nums2[l2] : INT_MAX;
if ((n1 + n2) & 1)
return min(rv1, rv2);
return (max(lv1, lv2) + min(rv1, rv2)) / 2.0;
}
};
Expand Down
4 changes: 2 additions & 2 deletions math/newton.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Solution:
<summary>详细代码</summary>
<!-- tabs:start -->

##### **C++**
##### **C++ 1**

```cpp
class Solution {
Expand All @@ -278,7 +278,7 @@ public:
};
```
##### **C++**
##### **C++ 2**
```cpp
class Solution {
Expand Down
2 changes: 2 additions & 0 deletions papers.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Papers

[github.com/binacs/paper](https://github.com/binacs/paper)

[github.com/binacs/blog](https://github.com/binacs/blog)
20 changes: 16 additions & 4 deletions resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,34 @@

## English

[Chinese Programmer Wrong Pronunciation](https://cpwp.netlify.app)

> https://github.com/antfu/cpwp
### Words

[most-frequent-technology-english-words](https://learn-english.dev)

> https://github.com/Wei-Xia/most-frequent-technology-english-words
[English-level-up-tips](https://github.com/byoungd/English-level-up-tips)
[Chinese Programmer Wrong Pronunciation](https://cpwp.netlify.app)

> https://github.com/antfu/cpwp
[interview-english](https://github.com/Interview-Science/interview-english)

### IELTS

[Salvation lies within IELTS](https://hefengxian.github.io/my-ielts/#/)

> https://github.com/hefengxian/my-ielts
### Type Training

[Qwerty Learner](https://qwerty.kaiyi.cool/)

[Eye Types](https://www.eletypes.com/)

### Others

[English-level-up-tips](https://github.com/byoungd/English-level-up-tips)

[A-Programmers-Guide-to-English](https://github.com/yujiangshui/A-Programmers-Guide-to-English)

## Quant
Expand Down
40 changes: 40 additions & 0 deletions topic/simulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5122,6 +5122,46 @@ class Solution:
<summary>详细代码</summary>
<!-- tabs:start -->

##### **C++ latest**

```cpp
class Solution {
public:
int divide(int x, int y) {
// ATTENTION 最小剪枝
if (x == INT_MIN && y == -1)
return INT_MAX;

bool is_minus = false;
if (x < 0 && y > 0 || x > 0 && y < 0) is_minus = true;
int a = x < 0 ? x : -x, b = y < 0 ? y : -y;

vector<int> exp;
// for (int i = b; i >= a; i = i + i) exp.push_back(i);
for (int i = b; i >= a; i = i + i) {
exp.push_back(i);
if (i < a / 2) // ATTENTION: pre check to void runtime error
break;
}

int res = 0;
for (int i = exp.size() - 1; i >= 0; i -- )
if (a <= exp[i]) {
a -= exp[i]; // 负数 所以同样要减
res += 1ll << i;
}

if (is_minus) {
if (res == INT_MIN)
return INT_MIN; // ATTENTION 细节 意味着 INT_MIN/1
return -res;
}
return res;
}
};
```


##### **C++ 1**

```cpp
Expand Down
26 changes: 25 additions & 1 deletion topic/trick.md
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,31 @@ class Solution:
<summary>详细代码</summary>
<!-- tabs:start -->

##### **C++**
##### **C++ 1**

```cpp
class Solution {
public:
int longestConsecutive(vector<int>& nums) {
int n = nums.size();
unordered_map<int, bool> m;
for (auto v : nums)
m[v] = true;
int res = 0;
for (auto v : nums) {
if (m[v - 1])
continue;
int cnt = 1;
while (m[ ++ v])
cnt ++ ;
res = max(res, cnt);
}
return res;
}
};
```
##### **C++ 2**
```cpp
class Solution {
Expand Down

0 comments on commit 49620ab

Please sign in to comment.