Skip to content

Commit ae93a77

Browse files
authored
Updated readme.
1 parent 80ddadc commit ae93a77

File tree

8 files changed

+587
-0
lines changed

8 files changed

+587
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@
11021102
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11031103
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------|----------|---------
11041104
| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15 | 1 | 100.00
1105+
| 0445 |[Add Two Numbers II](src/main/java/g0401_0500/s0445_add_two_numbers_ii)| Medium | Math, Stack, Linked_List, Programming_Skills_II_Day_15 | 3 | 81.96
11051106

11061107
#### Day 16
11071108

@@ -1292,6 +1293,7 @@
12921293
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12931294
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------|----------|---------
12941295
| 0197 |[Rising Temperature](src/main/java/g0101_0200/s0197_rising_temperature)| Easy | Database, SQL_I_Day_6_Union | 401 | 79.45
1296+
| 0607 |[Sales Person](src/main/java/g0601_0700/s0607_sales_person)| Easy | Database, SQL_I_Day_6_Union | 1046 | 86.04
12951297

12961298
#### Day 7 Function
12971299

@@ -1305,6 +1307,8 @@
13051307

13061308
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
13071309
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------|----------|---------
1310+
| 0586 |[Customer Placing the Largest Number of Orders](src/main/java/g0501_0600/s0586_customer_placing_the_largest_number_of_orders)| Easy | Database, SQL_I_Day_8_Function | 392 | 90.54
1311+
| 0511 |[Game Play Analysis I](src/main/java/g0501_0600/s0511_game_play_analysis_i)| Easy | Database, SQL_I_Day_8_Function | 620 | 35.70
13081312
| 1890 |[The Latest Login in 2020](src/main/java/g1801_1900/s1890_the_latest_login_in_2020)| Easy | Database, SQL_I_Day_8_Function | 571 | 73.59
13091313
| 1741 |[Find Total Time Spent by Each Employee](src/main/java/g1701_1800/s1741_find_total_time_spent_by_each_employee)| Easy | Database, SQL_I_Day_8_Function | 414 | 93.27
13101314

@@ -2528,6 +2532,7 @@
25282532
| 0611 |[Valid Triangle Number](src/main/java/g0601_0700/s0611_valid_triangle_number)| Medium | Array, Sorting, Greedy, Binary_Search, Two_Pointers, Binary_Search_II_Day_1 | 10 | 100.00
25292533
| 0609 |[Find Duplicate File in System](src/main/java/g0601_0700/s0609_find_duplicate_file_in_system)| Medium | Array, String, Hash_Table | 20 | 97.68
25302534
| 0608 |[Tree Node](src/main/java/g0601_0700/s0608_tree_node)| Medium | Database, SQL_I_Day_4_Union_and_Select | 347 | 95.17
2535+
| 0607 |[Sales Person](src/main/java/g0601_0700/s0607_sales_person)| Easy | Database, SQL_I_Day_6_Union | 1046 | 86.04
25312536
| 0606 |[Construct String from Binary Tree](src/main/java/g0601_0700/s0606_construct_string_from_binary_tree)| Easy | String, Depth_First_Search, Tree, Binary_Tree | 1 | 100.00
25322537
| 0605 |[Can Place Flowers](src/main/java/g0601_0700/s0605_can_place_flowers)| Easy | Array, Greedy | 1 | 96.77
25332538
| 0601 |[Human Traffic of Stadium](src/main/java/g0601_0700/s0601_human_traffic_of_stadium)| Hard | Database | 328 | 62.41
@@ -2543,6 +2548,7 @@
25432548
| 0590 |[N-ary Tree Postorder Traversal](src/main/java/g0501_0600/s0590_n_ary_tree_postorder_traversal)| Easy | Depth_First_Search, Tree, Stack | 0 | 100.00
25442549
| 0589 |[N-ary Tree Preorder Traversal](src/main/java/g0501_0600/s0589_n_ary_tree_preorder_traversal)| Easy | Depth_First_Search, Tree, Stack, Programming_Skills_I_Day_5_Function | 2 | 54.35
25452550
| 0587 |[Erect the Fence](src/main/java/g0501_0600/s0587_erect_the_fence)| Hard | Array, Math, Geometry | 10 | 87.50
2551+
| 0586 |[Customer Placing the Largest Number of Orders](src/main/java/g0501_0600/s0586_customer_placing_the_largest_number_of_orders)| Easy | Database, SQL_I_Day_8_Function | 392 | 90.54
25462552
| 0584 |[Find Customer Referee](src/main/java/g0501_0600/s0584_find_customer_referee)| Easy | Database, SQL_I_Day_1_Select | 505 | 43.87
25472553
| 0583 |[Delete Operation for Two Strings](src/main/java/g0501_0600/s0583_delete_operation_for_two_strings)| Medium | String, Dynamic_Programming, Algorithm_II_Day_17_Dynamic_Programming | 12 | 73.04
25482554
| 0581 |[Shortest Unsorted Continuous Subarray](src/main/java/g0501_0600/s0581_shortest_unsorted_continuous_subarray)| Medium | Array, Sorting, Greedy, Two_Pointers, Stack, Monotonic_Stack | 1 | 98.19
@@ -2592,6 +2598,7 @@
25922598
| 0515 |[Find Largest Value in Each Tree Row](src/main/java/g0501_0600/s0515_find_largest_value_in_each_tree_row)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 96.84
25932599
| 0514 |[Freedom Trail](src/main/java/g0501_0600/s0514_freedom_trail)| Hard | String, Dynamic_Programming, Depth_First_Search, Breadth_First_Search | 17 | 75.84
25942600
| 0513 |[Find Bottom Left Tree Value](src/main/java/g0501_0600/s0513_find_bottom_left_tree_value)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 80.06
2601+
| 0511 |[Game Play Analysis I](src/main/java/g0501_0600/s0511_game_play_analysis_i)| Easy | Database, SQL_I_Day_8_Function | 620 | 35.70
25952602
| 0509 |[Fibonacci Number](src/main/java/g0501_0600/s0509_fibonacci_number)| Easy | Dynamic_Programming, Math, Recursion, Memoization, Dynamic_Programming_I_Day_1 | 0 | 100.00
25962603
| 0508 |[Most Frequent Subtree Sum](src/main/java/g0501_0600/s0508_most_frequent_subtree_sum)| Medium | Hash_Table, Depth_First_Search, Tree, Binary_Tree | 6 | 77.55
25972604
| 0507 |[Perfect Number](src/main/java/g0501_0600/s0507_perfect_number)| Easy | Math | 2 | 73.73
@@ -2643,7 +2650,11 @@
26432650
| 0452 |[Minimum Number of Arrows to Burst Balloons](src/main/java/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons)| Medium | Array, Sorting, Greedy | 80 | 76.91
26442651
| 0451 |[Sort Characters By Frequency](src/main/java/g0401_0500/s0451_sort_characters_by_frequency)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Bucket_Sort, Data_Structure_II_Day_21_Heap_Priority_Queue | 18 | 70.93
26452652
| 0450 |[Delete Node in a BST](src/main/java/g0401_0500/s0450_delete_node_in_a_bst)| Medium | Tree, Binary_Tree, Binary_Search_Tree, Data_Structure_II_Day_16_Tree | 0 | 100.00
2653+
| 0449 |[Serialize and Deserialize BST](src/main/java/g0401_0500/s0449_serialize_and_deserialize_bst)| Medium | String, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Design, Binary_Search_Tree | 1 | 99.70
26462654
| 0448 |[Find All Numbers Disappeared in an Array](src/main/java/g0401_0500/s0448_find_all_numbers_disappeared_in_an_array)| Easy | Array, Hash_Table | 3 | 100.00
2655+
| 0447 |[Number of Boomerangs](src/main/java/g0401_0500/s0447_number_of_boomerangs)| Medium | Array, Hash_Table, Math | 156 | 80.44
2656+
| 0446 |[Arithmetic Slices II - Subsequence](src/main/java/g0401_0500/s0446_arithmetic_slices_ii_subsequence)| Hard | Array, Dynamic_Programming | 67 | 95.78
2657+
| 0445 |[Add Two Numbers II](src/main/java/g0401_0500/s0445_add_two_numbers_ii)| Medium | Math, Stack, Linked_List, Programming_Skills_II_Day_15 | 3 | 81.96
26472658
| 0443 |[String Compression](src/main/java/g0401_0500/s0443_string_compression)| Medium | String, Two_Pointers | 2 | 60.36
26482659
| 0442 |[Find All Duplicates in an Array](src/main/java/g0401_0500/s0442_find_all_duplicates_in_an_array)| Medium | Array, Hash_Table | 5 | 94.88
26492660
| 0441 |[Arranging Coins](src/main/java/g0401_0500/s0441_arranging_coins)| Easy | Math, Binary_Search, Binary_Search_I_Day_6 | 2 | 87.99
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
## 445\. Add Two Numbers II
2+
3+
Medium
4+
5+
You are given two **non-empty** linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
6+
7+
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2021/04/09/sumii-linked-list.jpg)
12+
13+
**Input:** l1 = [7,2,4,3], l2 = [5,6,4]
14+
15+
**Output:** [7,8,0,7]
16+
17+
**Example 2:**
18+
19+
**Input:** l1 = [2,4,3], l2 = [5,6,4]
20+
21+
**Output:** [8,0,7]
22+
23+
**Example 3:**
24+
25+
**Input:** l1 = [0], l2 = [0]
26+
27+
**Output:** [0]
28+
29+
**Constraints:**
30+
31+
* The number of nodes in each linked list is in the range `[1, 100]`.
32+
* `0 <= Node.val <= 9`
33+
* It is guaranteed that the list represents a number that does not have leading zeros.
34+
35+
**Follow up:** Could you solve it without reversing the input lists?
36+
37+
## Solution
38+
39+
```java
40+
import com_github_leetcode.ListNode;
41+
42+
/*
43+
* Definition for singly-linked list.
44+
* public class ListNode {
45+
* int val;
46+
* ListNode next;
47+
* ListNode() {}
48+
* ListNode(int val) { this.val = val; }
49+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
50+
* }
51+
*/
52+
public class Solution {
53+
private ListNode reverse(ListNode head) {
54+
if (head == null || head.next == null) return head;
55+
ListNode prev = null;
56+
ListNode curr = head;
57+
ListNode next = head.next;
58+
while (next != null) {
59+
curr.next = prev;
60+
prev = curr;
61+
curr = next;
62+
next = next.next;
63+
}
64+
curr.next = prev;
65+
return curr;
66+
}
67+
68+
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
69+
l1 = reverse(l1);
70+
l2 = reverse(l2);
71+
ListNode res = new ListNode();
72+
ListNode head = res;
73+
int carry = 0;
74+
while (l1 != null || l2 != null) {
75+
int val1;
76+
int val2;
77+
if (l1 == null) {
78+
val1 = 0;
79+
} else {
80+
val1 = l1.val;
81+
l1 = l1.next;
82+
}
83+
if (l2 == null) {
84+
val2 = 0;
85+
} else {
86+
val2 = l2.val;
87+
l2 = l2.next;
88+
}
89+
int data = val1 + val2 + carry;
90+
if (data > 9) {
91+
carry = data / 10;
92+
data = data % 10;
93+
} else {
94+
carry = 0;
95+
}
96+
res.next = new ListNode(data);
97+
res = res.next;
98+
}
99+
if (carry != 0) {
100+
res.next = new ListNode(carry);
101+
}
102+
return reverse(head.next);
103+
}
104+
}
105+
```
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
## 446\. Arithmetic Slices II - Subsequence
2+
3+
Hard
4+
5+
Given an integer array `nums`, return _the number of all the **arithmetic subsequences** of_ `nums`.
6+
7+
A sequence of numbers is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.
8+
9+
* For example, `[1, 3, 5, 7, 9]`, `[7, 7, 7, 7]`, and `[3, -1, -5, -9]` are arithmetic sequences.
10+
* For example, `[1, 1, 2, 5, 7]` is not an arithmetic sequence.
11+
12+
A **subsequence** of an array is a sequence that can be formed by removing some elements (possibly none) of the array.
13+
14+
* For example, `[2,5,10]` is a subsequence of `[1,2,1,**2**,4,1,**5**,**10**]`.
15+
16+
The test cases are generated so that the answer fits in **32-bit** integer.
17+
18+
**Example 1:**
19+
20+
**Input:** nums = [2,4,6,8,10]
21+
22+
**Output:** 7
23+
24+
**Explanation:** All arithmetic subsequence slices are:
25+
26+
[2,4,6]
27+
28+
[4,6,8]
29+
30+
[6,8,10]
31+
32+
[2,4,6,8]
33+
34+
[4,6,8,10]
35+
36+
[2,4,6,8,10]
37+
38+
[2,6,10]
39+
40+
**Example 2:**
41+
42+
**Input:** nums = [7,7,7,7,7]
43+
44+
**Output:** 16
45+
46+
**Explanation:** Any subsequence of this array is arithmetic.
47+
48+
**Constraints:**
49+
50+
* `1 <= nums.length <= 1000`
51+
* <code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code>
52+
53+
## Solution
54+
55+
```java
56+
import java.util.ArrayList;
57+
import java.util.HashMap;
58+
import java.util.List;
59+
import java.util.Map;
60+
61+
public class Solution {
62+
public int numberOfArithmeticSlices(int[] arr) {
63+
Map<Long, List<Integer>> indexes = new HashMap<>();
64+
int[][] length = new int[arr.length][arr.length];
65+
int count = 0;
66+
for (int i = 0; i < arr.length; i++) {
67+
for (int j = i + 1; j < arr.length; j++) {
68+
List<Integer> ix = indexes.get(arr[i] - (arr[j] - (long) arr[i]));
69+
if (ix == null) {
70+
continue;
71+
}
72+
for (int k : ix) {
73+
length[i][j] += length[k][i] + 1;
74+
}
75+
count += length[i][j];
76+
}
77+
indexes.computeIfAbsent((long) arr[i], k -> new ArrayList<>()).add(i);
78+
}
79+
return count;
80+
}
81+
}
82+
```
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## 447\. Number of Boomerangs
2+
3+
Medium
4+
5+
You are given `n` `points` in the plane that are all **distinct**, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. A **boomerang** is a tuple of points `(i, j, k)` such that the distance between `i` and `j` equals the distance between `i` and `k` **(the order of the tuple matters)**.
6+
7+
Return _the number of boomerangs_.
8+
9+
**Example 1:**
10+
11+
**Input:** points = \[\[0,0],[1,0],[2,0]]
12+
13+
**Output:** 2
14+
15+
**Explanation:** The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]].
16+
17+
**Example 2:**
18+
19+
**Input:** points = \[\[1,1],[2,2],[3,3]]
20+
21+
**Output:** 2
22+
23+
**Example 3:**
24+
25+
**Input:** points = \[\[1,1]]
26+
27+
**Output:** 0
28+
29+
**Constraints:**
30+
31+
* `n == points.length`
32+
* `1 <= n <= 500`
33+
* `points[i].length == 2`
34+
* <code>-10<sup>4</sup> <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>4</sup></code>
35+
* All the points are **unique**.
36+
37+
## Solution
38+
39+
```java
40+
import java.util.HashMap;
41+
42+
public class Solution {
43+
public int numberOfBoomerangs(int[][] points) {
44+
HashMap<Integer, Integer> m = new HashMap<>();
45+
int ans = 0;
46+
for (int i = 0; i < points.length; i++) {
47+
for (int j = 0; j < points.length; j++) {
48+
if (i == j) {
49+
continue;
50+
}
51+
int dis = dist(points[i], points[j]);
52+
int prev = m.getOrDefault(dis, 0);
53+
if (prev >= 1) ans += prev * 2;
54+
m.put(dis, prev + 1);
55+
}
56+
m.clear();
57+
}
58+
return ans;
59+
}
60+
61+
private int dist(int[] d1, int[] d2) {
62+
return (d1[0] - d2[0]) * (d1[0] - d2[0]) + (d1[1] - d2[1]) * (d1[1] - d2[1]);
63+
}
64+
}
65+
```

0 commit comments

Comments
 (0)