Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 0026.java in java and update README #60

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Java/0026.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Solution
{
public int removeDuplicates(int[] nums)
{
int dupes = 0;

for (int i = 1; i < nums.length; i++)
{
if (nums[i] == nums[i - 1])
dupes++;

nums[i - dupes] = nums[i];
}

return nums.length - dupes;
}
}
9 changes: 9 additions & 0 deletions Java/0136.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution {
public int singleNumber(int[] nums) {
int result=0;
for(int num : nums) {
result=result^num;
}
return result;
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Languages Used - C++, Java, Python3
| # | Title | Solution | Code | Time | Space | Difficulty | Tags | Video |
|------|------------------------------|-------------|-----------------|------|-------|------------|--------------|----------|
| 0001 | [2 Sum problem](https://leetcode.com/problems/two-sum/) | Check all the combinations by looping Map, if it’s complement (target - element) and exists then return the indices of the current element and the complement. | [C++](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/C++/0001.cpp) [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0001.java) | O(n) | O(1) | Easy | Hash Table Heap | [📺](https://www.youtube.com/watch?v=_ZEweLKQpY8) |
| 0021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)| Algo The strategy here uses a temporary dummy node as the start of the result list. The pointer Tail always points to the last node in the result list, so appending new nodes is easy. The dummy node gives the tail something to point to initially when the result list is empty. | [C++]() | O(m+n) | O(1) | Easy | Linked List | [📺](https://www.youtube.com/watch?v=vGiGh33WSew) |
| 0021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)| Algo The strategy here uses a temporary dummy node as the start of the result list. The pointer Tail always points to the last node in the result list, so appending new nodes is easy. The dummy node gives the tail something to point to initially when the result list is empty. | [C++]() | O(m+n) | O(1) | Easy | Linked List | [📺](https://youtu.be/a_2byCNCMeo) |
| 0026 | [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | Algo check and compare all the elments if equal then delete | [Java]() | O(n) | O(1) | Easy | Array | [📺](https://youtu.be/zIHe2V5Py3U) |
| 0027 | [Remove Element](https://leetcode.com/problems/remove-element/) | Two pointers for counting valid nos and swapping | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0027.java) [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0027.py) | O(n) | O(1) | Easy | Array Two Pointers | [📺](https://www.youtube.com/watch?v=r9HcLcYJBNc) |
| 0045 | [Jump Game II](https://leetcode.com/problems/jump-game-ii/) | newEnd = max(newEnd, i+nums[i]) | [C++](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/C++/0045.cpp) | O(n) | O(1) | Hard | Array Greedy | [📺](https://www.youtube.com/watch?v=hJ8EMc24O_M) |
| 0053 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | Parse array and save the best solution at each step | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0053.java) | O(n) | O(1) | Easy | Array Dynamic Programming | |
Expand All @@ -24,6 +25,7 @@ Languages Used - C++, Java, Python3
| 0101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | Check if left.left==right.right and left.right==right.left | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0101.java) | O(n) | O(h) | Easy | Tree Depth-first-Search Breadth-first-Search | [📺](https://www.youtube.com/watch?v=CgFsYbtRgQU) |
| 0104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | Depth = 1 + Max(depth of left, depth of right) | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0104.java) | O(n) | O(h) | Easy | Tree Depth-first-Search | [📺](https://www.youtube.com/watch?v=33YXh6wRVs4) |
| 0121 | [Best time to buy and sell stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | Minimize Cost price and Maximise Profit | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0121.java) | O(n) | O(1) | Easy | Array Dynamic Programming | [📺](https://www.youtube.com/watch?v=uc6gP5pZZ6I) |
| 0136 | [ Single Number]() | Algo ^ is the XOR operator. Let's assume we have an integer 'a'. So, a^a = 0 and a^0 = a | [Java]() | O(n) | O(1) | Easy | Bit manipulation | [📺](https://youtu.be/JqzSzefRgYY) |
| 0142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/) | Floyd’s Cycle detection algorithm | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master//Java/0142.java) | O(n) | O(1) | Medium | Linked List Two pointers | |
| 0200 | [Number of islands](https://leetcode.com/problems/number-of-islands/) | Merging adjacent lands, and the merging is done recursively | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0200.java) | O(n∗m) | O(1) | Medium | Depth-First Search Breadth-First Search| [📺](https://www.youtube.com/watch?v=vxhGsZWJRH4) |
| 0268 | [Missing Number](https://leetcode.com/problems/missing-number/) | Assuming that XOR is a constant-time operation, this algorithm does constant work on nn iterations, so the runtime is overall linear | [C++](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/C++/0268.cpp) [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0268.java) | O(n) | O(1) | Easy | Array Math BitManipulation | |
Expand Down