Skip to content

Instantly share code, notes, and snippets.

View linnykoleh's full-sized avatar
🎯
Focusing

Oleh Linnyk linnykoleh

🎯
Focusing
View GitHub Profile
@linnykoleh
linnykoleh / deleteDuplicates.java
Created March 24, 2017 14:23
Remove duplicates from sorted list II
public static ListNode deleteDuplicates(ListNode head) {
if(head == null) return null;
ListNode fake = new ListNode(-1);
fake.next = head;
ListNode pre = fake;
ListNode cur = head;
while(cur != null){
while(cur.next != null && cur.val == cur.next.val){
@linnykoleh
linnykoleh / pom.xml
Last active March 24, 2017 14:25
How to run only particular tests with failsafe plugin. Only from `folder3`
<profiles>
<profile>
<id>my-tests</id>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/stories/folder1/**</exclude>
@linnykoleh
linnykoleh / put.java
Created March 29, 2017 03:59
Hash map put node to array by key's hashcode
public V put(K key, V value) {
int hashCodeKey = hash(key);
return putVal(hashCodeKey, key, value);
}
private V putVal(int hashCodeKey, K key, V value) {
int newHashTableSize;
int indexForNode;
Node<K,V> nodeByHashCodeKey;
@linnykoleh
linnykoleh / get.java
Created March 29, 2017 04:02
Getting value from an array
public V get(Object key) {
final int hashCodeForKey = hash(key);
final Node<K,V> nodeByKey = getNode(hashCodeForKey, key);
return nodeByKey == null ? null : nodeByKey.value;
}
private Node<K,V> getNode(int hashCodeKey, Object keySearch) {
Node<K,V> current;
Node<K,V> next;
K keyForNode;
public class GoodKey {
private String a;
private String b;
public GoodKey(String a, String b) {
this.a = a;
this.b = b;
}
public class BadKey {
private String a;
private String b;
public BadKey(String a, String b) {
this.a = a;
this.b = b;
}
private static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
if(headA == null || headB == null){
return null;
}
final Set<ListNode> nodesA = new HashSet<>();
ListNode currentA = headA;
ListNode currentB = headB;
public ListNode deleteDuplicates(ListNode head) {
if(head == null || head.next == null)
return head;
ListNode current = head;
while(current != null && current.next != null){
if(current.val == current.next.val){
current.next = current.next.next;
}else{
public ListNode removeElements(ListNode head, int val) {
final ListNode fake = new ListNode(-1);
fake.next = head;
ListNode cur = fake;
while(cur.next != null){
if(cur.next.val == val){
cur.next = cur.next.next;
}else{
cur = cur.next;
public ListNode reverseBetween(ListNode head, int m, int n) {
if(head == null)
return null;
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode pre = dummy;
for(int i = 0; i < m-1; i++){
pre = pre.next;
}