Skip to content

Commit 143567d

Browse files
More crap
1 parent 36ce433 commit 143567d

File tree

3 files changed

+107
-9
lines changed

3 files changed

+107
-9
lines changed

Interview/Company/facebook/algorithm_prepare.md renamed to Interview/Algorithm/algorithm_prepare.md

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
9. [Maximum Swap](#Maximum-Swap) Medium
1313
10. [Intersection of Two Arrays](#Intersection-of-Two-Arrays) Easy
1414
11. [Intersection of Two Arrays II](#Intersection-of-Two-Arrays-II) Easy
15-
12. [Sparse Matrix Multiplication](#Sparse-Matrix-Multiplication) Medium
1615
13. [Rectangle Overlap](#Rectangle-Overlap) Easy
1716
14. [Minimum Window Substring](#Minimum-Window-Substring) Hard
1817
15. [Valid Number](#Valid-Number) Hard
@@ -21,11 +20,13 @@
2120
18. [Find the Kth largest item](#Find-the-Kth-largest-item) Medium
2221
19. [Count Duplicates](#Count-Duplicates) Medium
2322
20. [3 Sum](#3-Ssum)
23+
21. [Majority Item](Majority Item) Medium
2424

2525
## Matrix
2626
1. [Diagnose Tranverse](#Diagnose-Tranverse) Medium
2727
2. [Kth Smallest Element in a Sorted Matrix](#Kth-Smallest-Element-in-a-Sorted-Matrix) Medium
2828
3. [Rotate Image](#Rotate-Image) Medium
29+
4. [Sparse Matrix Multiplication](#Sparse-Matrix-Multiplication) Medium
2930

3031
## Binary Search
3132
1. [Search a 2D Matrix](#Search-a-2D-Matrix) Easy
@@ -49,7 +50,7 @@
4950
11. [Plus One Linked List](#Plus-One-Linked-List) Medium
5051
12. [Intersection of Two Linked Lists](#Intersection-of-Two-Linked-Lists) Medium
5152
13. [Remove Duplicates from Sorted List II](#Remove-Duplicates-from-Sorted-List-II) Medium
52-
14. [Remove Nth Node From End of List](#Remove-Nth node-from-the-end-of-list) Medium
53+
14. [Remove Nth Node From End of List](#Remove-Nth-node-from-the-end-of-list) Medium
5354

5455
## String
5556
1. [Valid Anagram](#Valid-Anagram) Easy
@@ -60,6 +61,7 @@
6061
1. [Is Power of Four](#Is-Power-of-Four) Easy
6162
2. [Range Bit And](#Range-Bit-And) Medium
6263
3. [Number Complement](#Number-Complement) Medium
64+
4. [Single Number II](#Single-Number-II) Medium
6365

6466
## Data Structure
6567
1. [LRU cache](#LRU-cache) Hard
@@ -86,6 +88,7 @@
8688
12. [Verifying a Alien Dictionary](#Verify-a-Alien-Dictionary) Medium
8789
13. [Container With Most Water](#Container-With-Most-Water) Medium
8890
14. [Move Zeroes](#Move-Zeroes) Medium
91+
15. [Symmetric Tree](#Symmetric-Tree) Easy
8992

9093
## Implementation
9194

@@ -3038,4 +3041,99 @@ public:
30383041
return sentinal.next;
30393042
}
30403043
};
3044+
```
3045+
3046+
### Symmetric Tree
3047+
***Big O:*** O(log(n)) speed, O(1) space
3048+
```
3049+
Tips:
3050+
3051+
Recursion.
3052+
```
3053+
```c++
3054+
class Solution {
3055+
public:
3056+
/**
3057+
* @param root: root of the given tree
3058+
* @return: whether it is a mirror of itself
3059+
*/
3060+
bool isSymmetric (TreeNode* root) {
3061+
// Write your code here
3062+
return root == nullptr || isSymmetricHelp (root->left, root->right);
3063+
}
3064+
bool isSymmetricHelp (TreeNode* left, TreeNode* right) {
3065+
if (left == nullptr || right == nullptr) {
3066+
return left == nullptr && right == nullptr;
3067+
}
3068+
if (left->val != right->val) {
3069+
return false;
3070+
}
3071+
return isSymmetricHelp (left->left, right->right) && isSymmetricHelp (left->right, right->left);
3072+
}
3073+
};
3074+
```
3075+
3076+
### Single Number II
3077+
***Big O:*** O(N) speed, O(1) space
3078+
```
3079+
Tips:
3080+
3081+
Counting Repeating Bits. If the mod with 3 is one, then that number must have this bit set.
3082+
```
3083+
```c++
3084+
class Solution {
3085+
public:
3086+
void count_bits(int arr[], int val) {
3087+
for (int i = 0; i < 32; i++) {
3088+
if (val & (0x1 << i))
3089+
arr[i] ++;
3090+
}
3091+
}
3092+
3093+
int singleNumber(vector<int>& nums) {
3094+
int arr[32] = {};
3095+
int ret = 0;
3096+
3097+
for (auto num : nums) {
3098+
count_bits(arr, num);
3099+
}
3100+
3101+
for (int i = 0; i < 32; i++) {
3102+
arr[i] = arr[i]%3;
3103+
ret |= (arr[i] << i);
3104+
}
3105+
3106+
return ret;
3107+
}
3108+
};
3109+
```
3110+
3111+
### Majority Item
3112+
***Big O:*** O(N) speed, O(1) space
3113+
```
3114+
Tips:
3115+
3116+
Counting Repeating Bits. If the bit position appears more than n/2 times, then we know it is for sure in the number.
3117+
```
3118+
```c++
3119+
class Solution {
3120+
public:
3121+
int majorityElement(vector<int>& nums) {
3122+
int n = nums.size();
3123+
int ans = 0, bits[32] = {0};
3124+
3125+
for (auto num : nums) {
3126+
for (int i = 0; i < 32; i++) {
3127+
bits[i] += ((num >> i) & 0x1);
3128+
}
3129+
}
3130+
3131+
for (int i = 0; i < 32; i++) {
3132+
if (bits[i] > n/2)
3133+
ans |= (1U << i);
3134+
}
3135+
3136+
return ans;
3137+
}
3138+
};
30413139
```
File renamed without changes.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
4. [sizeof](Data_Struct_Implementation/sizeof/README.md)
8888
5. [Aligned Malloc](Data_Struct_Implementation/alignedMalloc/README.md)
8989
6. Malloc()
90-
7. [strstr()](Data_Struct_Implementation\strstr\Makefile)
90+
7. [strstr()](Data_Struct_Implementation\strstr\README.md)
9191
14. Bits Manipulation
9292
1. [Reverse Bits](Data_Struct_Implementation/BitsManipulation/reverseBits.md)
9393
2. Flip a monochrome bitmap
@@ -348,11 +348,12 @@
348348

349349
### [A. LeetCode Questions for Embedded Developers](Interview/Algorithm/LeetCode_for_Embedded_Developer.md)
350350
1. [Advanced Leetcode Questions](Interview/Algorithm/LeetCode_for_embedded_advanced.md)
351-
2. [Linked list](Interview/Algorithm/linked_list.md)
352-
3. [String]((Interview/Algorithm/string.md))
353-
4. [Array](Interview/Algorithm/Array.md)
354-
5. [Math](Interview/Algorithm/math.md)
355-
6. [Data Structure](Interview/Algorithm/dataStructure.md)
351+
2. [Advanced Leetcode Questions Practices](Interview\Algorithm\algorithm_prepare.md)
352+
3. [Linked list](Interview/Algorithm/linked_list.md)
353+
4. [String]((Interview/Algorithm/string.md))
354+
5. [Array](Interview/Algorithm/Array.md)
355+
6. [Math](Interview/Algorithm/math.md)
356+
7. [Data Structure](Interview/Algorithm/dataStructure.md)
356357

357358
### B. Other Algorithms Questions
358359
1. Sliding Window
@@ -476,7 +477,6 @@
476477
8. [Amazon](Interview/Company/amazon.md)
477478
9. [Lyft](Interview/Company/lyft.md)
478479
10. [FaceBook](Interview/Company/facebook.md)
479-
1. [Algorithm Prepare](Interview/Company/facebook/algorithm_prepare.md)
480480
11. Zoox
481481
12. [Apple](Interview/Company/apple.md)
482482

0 commit comments

Comments
 (0)