File tree 5 files changed +75
-4
lines changed
5 files changed +75
-4
lines changed Original file line number Diff line number Diff line change 6
6
7
7
## 位运算
8
8
9
- No.136 [ cpp] ( cpp/136.cpp )
9
+ + No.136 [ cpp] ( cpp/136.cpp )
10
+ + No.64 [ cpp] ( cpp/64.cpp ) [ python] ( python/64.py )
10
11
11
12
### 散列表(HashTable)
12
13
@@ -15,7 +16,7 @@ No.136 [cpp](cpp/136.cpp)
15
16
16
17
## 二叉树
17
18
18
- #### 二叉树的遍历
19
+ ### 二叉树的遍历
19
20
20
21
+ No.113: [ cpp] ( cpp/113.cpp ) [ python] ( python/113.py )
21
22
@@ -37,8 +38,12 @@ No.136 [cpp](cpp/136.cpp)
37
38
38
39
## 前缀和/树状数组
39
40
40
- No.303 [ cpp] ( cpp/303.cpp )
41
- No.307 [ cpp] ( cpp/307.cpp )
41
+ + No.303 [ cpp] ( cpp/303.cpp )
42
+ + No.307 [ cpp] ( cpp/307.cpp )
43
+
44
+ ## 二分
45
+
46
+ + No.128 [ cpp] ( cpp/128.cpp ) [ python] ( python/128.py )
42
47
43
48
### 剑指offer系列
44
49
Original file line number Diff line number Diff line change
1
+ #include < algorithm>
2
+ #include < vector>
3
+ using namespace std ;
4
+
5
+ class Solution {
6
+ public:
7
+ int smallestDivisor (vector<int >& nums, int threshold) {
8
+ int end = *max_element (nums.cbegin (), nums.cend ());
9
+ int begin = 1 ;
10
+ int mid, _sum, res = -1 ;
11
+ while (end > begin) {
12
+ mid = (end - begin)/2 + begin;
13
+ _sum = 0 ;
14
+ for (int num: nums) {
15
+ _sum += (num - 1 + mid)/mid;
16
+ }
17
+
18
+ if (_sum > threshold) {
19
+ begin = mid+1 ;
20
+ } else {
21
+ end = mid;
22
+ }
23
+ }
24
+ return end;
25
+
26
+ }
27
+
28
+
29
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int sumNums (int n) {
4
+ int sum = 0 ;
5
+ _sum (n, sum);
6
+ return sum;
7
+ }
8
+ int _sum (int n, int &sum) {
9
+ sum += n;
10
+ return n && _sum (n-1 , sum);
11
+ }
12
+ };
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def smallestDivisor (self , nums : List [int ], threshold : int ) -> int :
3
+ begin , end = 1 , max (nums )+ 1
4
+ while begin < end :
5
+ mid = (end - begin )// 2 + begin
6
+ _sum = 0
7
+ for num in nums :
8
+ _sum += (num + mid - 1 ) // mid
9
+ if _sum <= threshold :
10
+ end = mid
11
+ else :
12
+ begin = mid + 1
13
+ return end
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def sumNums (self , n : int ) -> int :
3
+ """
4
+ 使用and运算符短路
5
+ """
6
+ sum_val = 0
7
+ def _sum (n ):
8
+ nonlocal sum_val
9
+ sum_val += n
10
+ return n and _sum (n - 1 )
11
+ _sum (n )
12
+ return sum_val
You can’t perform that action at this time.
0 commit comments