This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int missingNumber(int[] nums) { | |
Arrays.sort(nums); | |
int n = 0; | |
for(int i = 0; i < nums.length; i++, n++){ | |
if(n !=nums[i]) | |
return n; | |
} | |
return nums[nums.length-1]+1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrieNode { | |
// Initialize your data structure here. | |
public Character key; | |
public boolean isWordEnd = false; | |
private Map<Character, TrieNode> childs; | |
public TrieNode(Character key, boolean isWordEnd) { | |
this.key = key; | |
childs = new HashMap<Character,TrieNode>(); | |
this.isWordEnd = isWordEnd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean search (String word, boolean isPrefix){ | |
char[] data = word.toCharArray(); | |
TrieNode node = root; | |
for(char c:data){ | |
node = node.getChild(c); | |
if(node == null) | |
return false; | |
} | |
return isPrefix ? true: node.isWordEnd; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrieNode { | |
// Initialize your data structure here. | |
public Character key; | |
public boolean isWordEnd = false; | |
private Map<Character, TrieNode> childs; | |
public TrieNode(Character key, boolean isWordEnd) { | |
this.key = key; | |
childs = new HashMap<Character,TrieNode>(); | |
this.isWordEnd = isWordEnd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inserts a word into the trie. | |
public void insert(String word) { | |
char[] data = word.toCharArray(); | |
TrieNode node = root; | |
for(int i = 0; i < data.length; i++){ | |
node = insert(node, data[i], (i+1 == data.length)); | |
} | |
} | |
public TrieNode insert(TrieNode node, Character c, boolean isLastLetter) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.playtika.rest; | |
import javax.ws.rs.core.Response; | |
/** | |
* @author szagriichuk | |
*/ | |
public final class ResponseStatus{ | |
private Response.Status status = Response.Status.OK; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.playtika.events; | |
/** | |
* @author szagriichuk | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
EventsBus<MyEvent,String> eventBusSimple = new EventsBus<MyEvent,String>(); | |
eventBusSimple.register(new MyEventSubscriberSimple()); | |
System.out.println(toDoSomethingSimple(eventBusSimple)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.playtika.events; | |
import com.google.common.eventbus.EventBus; | |
/** | |
* @author szagriichuk | |
*/ | |
public class EventsBus{ | |
public static void main(String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int longestValidParentheses(String s) { | |
if(s == null || s.length() == 0 ) | |
return 0; | |
Stack<Integer> stack = new Stack<Integer>(); | |
int longest = 0; | |
int last = -1; // -1 case | |
for(int i = 0; i < s.length(); i++){ | |
if(s.charAt(i) == '('){ | |
stack.add(i); | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int longestValidParentheses(String s) { | |
if(s.length() == 0 ) | |
return 0; | |
return Math.max(findLongest(s, 0, s.length()-1, 1, '('), | |
findLongest(s, s.length()-1, -1,-1, ')')); | |
} | |
private int findLongest(String s, int start, int end, int step, char ch) { | |
Stack<String> stack = new Stack<String>(); | |
int longest = 0; |
NewerOlder