Skip to content

Commit 146db41

Browse files
committed
10/01
1 parent c45e0d7 commit 146db41

7 files changed

Lines changed: 176 additions & 1 deletion

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Feel free to add issues, comment and pull request.
3939
| Leetcode | [611. Valid Triangle Number](https://leetcode.com/problems/valid-triangle-number/description/) | [Java](./java/triangleNumber.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
4040
| Leetcode | [561. Array Partition I](https://leetcode.com/problems/array-partition-i/description/) | [Java](./java/arrayPairSum.java) \| [Python](./Python/) | _O(nlogn)_ | _O(1)_ | Easy | |
4141
| Leetcode | [611. Valid Triangle Number](https://leetcode.com/problems/valid-triangle-number/description/) | [Java](./java/triangleNumber.java) \| [Python](./Python/) | _O()_ | _O()_ | Medium | |
42+
| Leetcode | [66. Plus One](https://leetcode.com/problems/plus-one/description/) | [Java](./java/plusOne.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
43+
| Leetcode | [88. Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/description/) | [Java](./java/merge.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
4244

4345

4446

@@ -75,7 +77,7 @@ Feel free to add issues, comment and pull request.
7577
| Leetcode | [623. Add One Row to Tree](https://leetcode.com/problems/add-one-row-to-tree/description/) | [Java](./java/addOneRow.java) \| [Python](./Python/) | | | Medium | |
7678
| Leetcode | [662. Maximum Width of Binary Tree](https://leetcode.com/problems/maximum-width-of-binary-tree/description/) | [Java](./java/widthOfBinaryTree.java) \| [Python](./Python/) | O(n) | O(d) | Medium | |
7779
| Leetcode | [606. Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree/description/) | [Java](./java/tree2str.java) \| [Python](./Python/) | O(n) | O(1) | Easy | |
78-
80+
| Leetcode | [101. Symmetric Tree](https://leetcode.com/problems/symmetric-tree/description/) | [Java](./java/isSymmetric.java) \| [Python](./Python/) | O(n) | O(1) | Easy | |
7981

8082
## Dynamic Programming
8183
| Website | Title | Solution | Time | Space | Difficulty | Note|
@@ -86,6 +88,7 @@ Feel free to add issues, comment and pull request.
8688
| Leetcode | [62. Unique Paths](https://leetcode.com/problems/unique-paths/) | [Java](./java/UniquePaths.java) \| [Python](./Python/) | _O(m*n)_ | _O(m+n)_ | Easy | |
8789
| Leetcode | [62. Unique Paths](https://leetcode.com/problems/maximum-length-of-pair-chain/description/) | [Java](./java/findLongestChain.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
8890
| Leetcode | [264. Ugly Number II](https://leetcode.com/problems/ugly-number-ii/description/) | [Java](./java/nthUglyNumber.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
91+
| Leetcode | [70. Climbing Stairs](https://leetcode.com/problems/climbing-stairs/description/) | [Java](./java/nthUglyNumber.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
8992

9093

9194
## Recursion
@@ -125,10 +128,16 @@ Feel free to add issues, comment and pull request.
125128
|---------------- |---------------- | ----------- | --------------- | --------------- | ------------- |-----|
126129
| Leetcode | [328. Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list/description/) | [Java](./java/oddEvenList.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Medium | |
127130
| Leetcode | [23. Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/description/) | [Java](./java/mergeKLists.java) \| [Python](./Python/) | _O(n logk)_ | _O(1)_ | Medium | |
131+
| Leetcode | [83. Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/) | [Java](./java/deleteDuplicates.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
128132

129133

130134
## TwoPointers
131135
| Website | Title | Solution | Time | Space | Difficulty | Note|
132136
|---------------- |---------------- | ----------- | --------------- | --------------- | ------------- |-----|
133137
| Leetcode | [680. Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii/description/) | [Java](./java/validPalindrome.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
134138

139+
## BFS
140+
| Website | Title | Solution | Time | Space | Difficulty | Note|
141+
|---------------- |---------------- | ----------- | --------------- | --------------- | ------------- |-----|
142+
| Leetcode | [690. Employee Importance](https://leetcode.com/problems/employee-importance/description/) | [Java](./java/getImportance.java) \| [Python](./Python/) | _O(v+e)_ | _O(1)_ | Easy | |
143+

java/deleteDuplicates.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) { val = x; }
7+
* }
8+
*/
9+
class Solution {
10+
public ListNode deleteDuplicates(ListNode head) {
11+
12+
ListNode cur = head;
13+
while(cur != null)
14+
{
15+
if(cur.next == null)
16+
return head;
17+
if(cur.val == cur.next.val)
18+
cur.next = cur.next.next;
19+
else
20+
cur = cur.next;
21+
}
22+
return head;
23+
24+
}
25+
}

java/getImportance.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
// Employee info
3+
class Employee {
4+
// It's the unique id of each node;
5+
// unique id of this employee
6+
public int id;
7+
// the importance value of this employee
8+
public int importance;
9+
// the id of direct subordinates
10+
public List<Integer> subordinates;
11+
};
12+
*/
13+
class Solution {
14+
public int getImportance(List<Employee> employees, int id) {
15+
16+
int importance = 0;
17+
18+
HashMap<Integer, Employee> map = new HashMap<>();
19+
for(Employee employee : employees)
20+
map.put(employee.id, employee);
21+
22+
Queue<Employee> queue = new LinkedList<>();
23+
queue.offer(map.get(id));
24+
25+
while(!queue.isEmpty())
26+
{
27+
Employee node = queue.poll();
28+
importance += node.importance;
29+
for(int subor: node.subordinates)
30+
queue.offer(map.get(subor));
31+
}
32+
return importance;
33+
}
34+
}

java/intersection.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
3+
Using HashSet
4+
Time complexity O(n)
5+
Space Complexity O(n)
6+
7+
*/
8+
9+
class Solution {
10+
public int[] intersection(int[] nums1, int[] nums2) {
11+
12+
HashSet<Integer> set = new HashSet<>();
13+
HashSet<Integer> result = new HashSet<>();
14+
15+
for(int num: nums1)
16+
set.add(num);
17+
18+
for(int num: nums2)
19+
if(set.contains(num))
20+
result.add(num);
21+
22+
int [] resultArray = new int[result.size()];
23+
int i = 0;
24+
25+
for(int num: result)
26+
resultArray[i++] = num;
27+
28+
return resultArray;
29+
30+
}
31+
}
32+
33+
/*
34+
35+
Using Sorting and Two pointers
36+
Time complexity O(nlogn)
37+
Space complexity O(1)
38+
39+
*/
40+
41+
42+

java/isSymmetric.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode(int x) { val = x; }
8+
* }
9+
*/
10+
class Solution {
11+
public boolean isSymmetric(TreeNode root) {
12+
13+
if(root == null)
14+
return true;
15+
return helper(root.left, root.right);
16+
17+
}
18+
19+
public boolean helper(TreeNode p, TreeNode q)
20+
{
21+
if(p == null && q == null)
22+
return true;
23+
if(p == null || q == null)
24+
return false;
25+
return p.val == q.val && helper(p.left, q.right) && helper(p.right, q.left);
26+
}
27+
}

java/merge.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public void merge(int[] nums1, int m, int[] nums2, int n) {
3+
4+
int i = m-1, j=n-1, k = m+n-1;
5+
6+
while(i >=0 && j >=0)
7+
{
8+
if(nums1[i] > nums2[j])
9+
nums1[k--] = nums1[i--];
10+
else
11+
nums1[k--] = nums2[j--];
12+
}
13+
14+
while(j >= 0)
15+
nums1[k--] = nums2[j--];
16+
17+
}
18+
}

java/plusOne.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int[] plusOne(int[] digits) {
3+
int n = digits.length;
4+
5+
for(int i=n-1; i>=0; i--)
6+
{
7+
if(digits[i]<9)
8+
{
9+
digits[i]++;
10+
return digits;
11+
}
12+
digits[i]=0;
13+
}
14+
15+
int [] newNumber = new int[n+1];
16+
newNumber[0]=1;
17+
return newNumber;
18+
19+
}
20+
}

0 commit comments

Comments
 (0)