Skip to content

Clone graph #1

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

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e16cc7d
Adding the easy solution for implmenting hamming distance code logic
pratikpalashikar Jul 24, 2018
da76550
Merge remote-tracking branch 'origin/master'
pratikpalashikar Jul 24, 2018
0630ad6
Update Readme
pratikpalashikar Jul 24, 2018
07298e7
Adding the easy solution for implmenting middle element in linked list
pratikpalashikar Jul 31, 2018
17fda44
Adding the easy solution for implmenting middle element in linked list
pratikpalashikar Jul 31, 2018
afe5952
Commiting JudgeCircle problem statement solution
pratikpalashikar Aug 14, 2018
6e8fa7e
updating readme
pratikpalashikar Aug 14, 2018
ae60571
Commiting JudgeCircle test case
pratikpalashikar Aug 16, 2018
2555a69
Merge remote-tracking branch 'origin/master'
pratikpalashikar Aug 16, 2018
1fb8a5f
Commiting parentheses test case
pratikpalashikar Sep 8, 2018
e285e81
Parentheses tetsing with some test cases and fixing the test cases
pratikpalashikar Sep 8, 2018
4dbcbfb
Parentheses tetsing with some test cases and fixing the test cases
pratikpalashikar Sep 8, 2018
f05e5f9
Parentheses tetsing with some test cases and fixing the test cases
pratikpalashikar Sep 8, 2018
f222897
Parentheses tetsing with some test cases and fixing the test cases
pratikpalashikar Sep 8, 2018
015af24
Update README.md
pratikpalashikar Sep 9, 2018
fb5203b
PlusOne to the arrays
pratikpalashikar Sep 9, 2018
2489d62
Merge remote-tracking branch 'origin/master'
pratikpalashikar Sep 9, 2018
b45b0fe
updated the readme
pratikpalashikar Sep 9, 2018
42b59e9
updated the readme
pratikpalashikar Sep 9, 2018
86e4e79
Update README.md
pratikpalashikar Sep 9, 2018
c64df78
implemented the minstack using one stack
pratikpalashikar Sep 12, 2018
07efc34
implemented the minstack using one stack
pratikpalashikar Sep 12, 2018
94bd771
Update README.md
pratikpalashikar Sep 12, 2018
1270644
Maximum Sub Array solution in java
Arihant1467 Oct 12, 2018
64a63cc
Merge pull request #5 from Arihant1467/patch-1
pratikpalashikar Oct 12, 2018
4cff287
Update CONTRIBUTING.md
pratikpalashikar Oct 12, 2018
d42f0c6
Revert "Maximum Sub Array solution in java"
pratikpalashikar Oct 12, 2018
7d51b01
Merge pull request #45 from pratikpalashikar/revert-5-patch-1
pratikpalashikar Oct 12, 2018
4666d00
Adding jupiter to enable displayName feature on test
martabacc Oct 12, 2018
83782b7
Add solution and tests for Number of Islands
martabacc Oct 12, 2018
38e968a
Updating readme
martabacc Oct 12, 2018
05ddc2e
Fix typo
martabacc Oct 12, 2018
c9289cc
Merge pull request #46 from ronayumik/master
pratikpalashikar Oct 12, 2018
e55451f
Solved Search a 2D Matrix II
Oct 12, 2018
f10deef
updating link to correct problems solutions
pratikpalashikar Oct 13, 2018
05194e2
vertical order traversal
varshika15 Oct 13, 2018
e4fe5c8
Add solution for Maximum product of word lengths
Oct 13, 2018
6c0eccc
Add solution of Super Ugly Number.
Oct 13, 2018
62ec412
Added perfect square
varshika15 Oct 14, 2018
819885d
Added WiggleSort
Oct 14, 2018
bd9746e
Fixed syntax and comments
Oct 14, 2018
d75e41a
Fixed syntax (again)
Oct 14, 2018
54757be
switched test and main
Oct 14, 2018
e9e4220
renamed test file
Oct 14, 2018
0d09032
imported assert
Oct 14, 2018
6f6df00
fix: assertArrayEquals
Oct 14, 2018
5807627
Corrected Name to Wiggle Sort II
Oct 14, 2018
0c9dd28
changed class names to match files
Oct 14, 2018
b7675a3
Merge pull request #49 from leptepkt/master
pratikpalashikar Oct 14, 2018
d086c3f
Merge branch 'master' into master
pratikpalashikar Oct 14, 2018
55b7302
Merge pull request #50 from ddbullfrog/master
pratikpalashikar Oct 14, 2018
701160b
Checkpoint before refactor to new way
martabacc Oct 15, 2018
a240a4f
Fix bug on vertices iterator
martabacc Oct 15, 2018
8209d69
Last checkpoint, fixing one later
martabacc Oct 15, 2018
ebed183
Add solution of Summary Ranges.
Oct 16, 2018
e92cac0
Merge pull request #48 from varshika15/master
pratikpalashikar Oct 16, 2018
4bfbc55
Merge branch 'master' into master
pratikpalashikar Oct 16, 2018
6ef3dc8
Merge pull request #60 from ddbullfrog/summary_ranges
pratikpalashikar Oct 16, 2018
cb57e96
Fix uncovered testcase
martabacc Oct 17, 2018
4e55402
add readme
martabacc Oct 17, 2018
23257d7
Merge branch 'master' into master
martabacc Oct 17, 2018
b73e28a
Merge pull request #56 from ronayumik/master
pratikpalashikar Oct 18, 2018
98562a2
Merge pull request #47 from s-fletcher/master
pratikpalashikar Nov 6, 2018
1c4e6a4
Merge pull request #51 from Sinitax/add-wigglesort
pratikpalashikar Nov 6, 2018
b8264be
Clone Graph
HuskyNator Oct 22, 2019
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
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
- When writing solution for a given problem add the problem statement above the class as comment
- Write test case for each of the problem statement and make sure it builds with Travis CI
- Add the code link in the readme.md file with problem description and the link to the problem solution


- Give a star to the repo
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@ Stop thinking start contributing to leetcode solution
- [FindAllAnagramsInString](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/FindAllAnagramsInString.java)
- [TransposeMatrix](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/TransposeMatrix.java)
- [LowerCase](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/LowerCase.java)


- [HammingDistance](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/HammingDistance.java)
- [MiddleElementInLinkedList](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/MiddleElement.java)
- [JudgeCircle](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/JudgeCircle.java)
- [Parentheses](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/Parentheses.java)
- [PlusOne](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/PlusOne.java)
- [MinStack](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/MinStack.java)

### Medium


- [ValidSudoku](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/ValidSudoku.java)
- [GroupAnagrams](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/GroupAnagrams.java)
- [NumberOfIslands](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/NumberOfIslands.java)
- [SearchA2DMatrixII](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/SearchA2DMatrixII.java)
- [ValidSudoku](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/ValidSudoku.java)
- [GroupAnagrams](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/GroupAnagrams.java)
- [NumberOfIslands](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/NumberOfIslands.java)
- [SuperUglyNumber](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/SuperUglyNumber.java)
- [MaximumProductOfWordLengths](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/MaximumProductOfWordLengths.java)
- [SummaryRanges](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/SummaryRanges.java)
- [MinimumHeightTree](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/MinimumHeightTree.java)
- [CloneGraph](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/CloneGraph.java)


### Hard

- [SudokuSolver](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/hard/SudokuSolver.java)
- [SudokuSolver](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/hard/SudokuSolver.java)
31 changes: 31 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[![Build Status](https://travis-ci.org/pratikpalashikar/leetcode-solutions.svg?branch=master)](https://travis-ci.org/pratikpalashikar/leetcode-solutions)

# leetcode-solutions
Stop thinking start contributing to leetcode solution


## Solution Lists

### Easy

- [JewelsNStones](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/JewelsNStones.java)
- [ValidAnagram](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/ValidAnagram.java)
- [FindAllAnagramsInString](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/FindAllAnagramsInString.java)
- [TransposeMatrix](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/TransposeMatrix.java)
- [LowerCase](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/LowerCase.java)
- [HammingDistance](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/HammingDistance.java)
- [MiddleElementInLinkedList](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/MiddleElement.java)
- [JudgeCircle](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/JudgeCircle.java)
- [Parentheses](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/Parentheses.java)
- [PlusOne](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/PlusOne.java)
- [MinStack](https://github.com/pratikpalashikar/leetcode-solutions/blob/master/src/main/java/com/techmisal/easy/MinStack.java)

### Medium

- [ValidSudoku](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/ValidSudoku.java)
- [GroupAnagrams](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/GroupAnagrams.java)
- [NumberOfIslands](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/medium/NumberOfIslands.java)

### Hard

- [SudokuSolver](https://github.com/harmishlakhani/leetcode-solutions/blob/master/src/main/java/com/techmisal/hard/SudokuSolver.java)
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand All @@ -41,4 +47,4 @@
</build>


</project>
</project>
45 changes: 45 additions & 0 deletions src/main/java/com/techmisal/easy/HammingDistance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.techmisal.easy;


/*

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, calculate the Hamming distance.

Note:
0 ≤ x, y < 231.

Example:

Input: x = 1, y = 4

Output: 2

Explanation:
1 (0 0 0 1)
4 (0 1 0 0)
↑ ↑

The above arrows point to positions where the corresponding bits are different.

*/

import java.util.ArrayList;
import java.util.List;

public class HammingDistance {

public int hammingDistance(int x, int y) {



return Integer.bitCount(x^y);


}




}
55 changes: 55 additions & 0 deletions src/main/java/com/techmisal/easy/JudgeCircle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.techmisal.easy;

/*

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.

The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are R (Right), L (Left), U (Up) and D (down). The output should be true or false representing whether the robot makes a circle.

Example 1:
Input: "UD"
Output: true
Example 2:
Input: "LL"
Output: false


*/



public class JudgeCircle {


public boolean judgeCircleMethod(String moves) {



int X=0;
int Y=0;


for(int i=0;i<moves.length();i++){

if(moves.charAt(i)=='U')
X++;
if(moves.charAt(i)=='D')
X--;
if(moves.charAt(i)=='L')
Y--;
if(moves.charAt(i)=='R')
Y++;

}

if(X==0 && Y==0){
return true;
}


return false;

}


}
66 changes: 66 additions & 0 deletions src/main/java/com/techmisal/easy/MiddleElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.techmisal.easy;

/*

Given a non-empty, singly linked list with head node head, return a middle node of linked list.

If there are two middle nodes, return the second middle node.



Example 1:

Input: [1,2,3,4,5]
Output: Node 3 from this list (Serialization: [3,4,5])
The returned node has value 3. (The judge's serialization of this node is [3,4,5]).
Note that we returned a ListNode object ans, such that:
ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL.
Example 2:

Input: [1,2,3,4,5,6]
Output: Node 4 from this list (Serialization: [4,5,6])
Since the list has two middle nodes with values 3 and 4, we return the second one.


Note:

The number of nodes in the given list will be between 1 and 100.


*/


class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }

}

public class MiddleElement {

public ListNode middleNode(ListNode head) {

if(head==null){
return head;
}

if(head.next == null){
return head;
}



ListNode slow = head;
ListNode fast = head;

while(fast!=null && fast.next!=null){
slow = slow.next;
fast = fast.next.next;
}


return slow;

}
}
69 changes: 69 additions & 0 deletions src/main/java/com/techmisal/easy/MinStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.techmisal.easy;

import java.util.Stack;


/*


Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

push(x) -- Push element x onto stack.
pop() -- Removes the element on top of the stack.
top() -- Get the top element.
getMin() -- Retrieve the minimum element in the stack.
Example:
MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin(); --> Returns -3.
minStack.pop();
minStack.top(); --> Returns 0.
minStack.getMin(); --> Returns -2.


*/

public class MinStack {

int min = Integer.MAX_VALUE;

public Stack<Integer> stack = new Stack<Integer>();


public void pop() {


if (stack.pop() == min) {

min = stack.pop();

}

}


public void push(int x) {

if (x <= min) {
stack.push(min);
min = x;
}

stack.push(x);

}


public int getMin() {

return min;
}


public int top() {

return stack.peek();
}
}
Loading