Skip to content

Commit daf3336

Browse files
Update
1 parent f446b35 commit daf3336

File tree

189 files changed

+64
-156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+64
-156
lines changed

1962-remove-stones-to-minimize-the-total/1962-remove-stones-to-minimize-the-total.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

2129-capitalize-the-title/2129-capitalize-the-title.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

2515-shortest-distance-to-target-string-in-a-circular-array/NOTES.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

2520-count-the-digits-that-divide-a-number/NOTES.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
int main() {
3+
int leftmost = -1;
4+
int left = 0, right = nums.length - 1;
5+
while (left <= right) {
6+
mid = (left + right) / 2;
7+
if (nums[mid] < target) {
8+
left = mid + 1;
9+
} else if (nums[mid] > target) {
10+
right = mid - 1;
11+
} else {
12+
// binary search for leftmost index
13+
leftmost = mid;
14+
right = mid - 1;
15+
}
16+
}
17+
18+
left = 0; right = nums.length - 1;
19+
int rightmost = -1;
20+
while (left <= right) {
21+
mid = (left + right) / 2;
22+
if (nums[mid] < target) {
23+
left = mid + 1;
24+
} else if (nums[mid] > target) {
25+
right = mid - 1;
26+
} else {
27+
// binary search for rightmost index
28+
rightmost = mid;
29+
left = mid + 1;
30+
}
31+
}
32+
}

code/algorithms/union-find.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class UnionFind {
1212
int rootY = find(y);
1313
if (rootX != rootY)
1414
for (int i = 0; i < root.size(); i++)
15-
if (root[i] == rootY) root[i] = rootX;
15+
if (root[i] == rootY)
16+
root[i] = rootX;
1617
}
1718

1819
bool connected(int x, int y) {
File renamed without changes.

0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.cpp renamed to leetcode/0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.cpp

File renamed without changes.

0 commit comments

Comments
 (0)