This file contains hidden or 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 Solution { | |
public int solution(int N) { | |
// write your code in Java SE 8 | |
int fac=0; | |
int count=0; | |
for(int index=(int)Math.sqrt(N);index>0;index--){ | |
fac=N/index; | |
if(fac*index==N){count=count+2; | |
if(fac==index){count-=1;}} |
This file contains hidden or 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
import java.math.BigInteger; | |
import java.util.Random; | |
class Solution { | |
private static final Random rnd = new Random(); | |
public static boolean miller_rabin(BigInteger n) { | |
for (int repeat = 0; repeat < 20; repeat++) { | |
BigInteger a; | |
do { | |
a = new BigInteger(n.bitLength(), rnd); | |
} while (a.equals(BigInteger.ZERO)); |
This file contains hidden or 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 solution(int[] A) { | |
int ans = A[0]; | |
int sum = 0; | |
for (int i = 0; i < A.length; i++) { | |
if (sum > 0) { | |
sum += A[i]; | |
} else { | |
sum = A[i]; | |
} |
This file contains hidden or 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 Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
if(A.length==0){ | |
return 0; | |
} | |
int ans=0; | |
int min=Integer.MAX_VALUE; |
This file contains hidden or 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
import java.util.Stack; | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
if(A.length==0){ | |
return -1; | |
} | |
Stack<Integer> stack=new Stack<Integer>(); | |
int size=0; | |
int dominatorIndex=0; |
This file contains hidden or 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
// you can also use imports, for example: | |
// import java.util.*; | |
// you can use System.out.println for debugging purposes, e.g. | |
// System.out.println("this is a debug message"); | |
import java.util.Stack; | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
Stack<Integer> stack=new Stack<Integer>(); |
This file contains hidden or 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
import java.util.Stack; | |
class Solution { | |
public int solution(int[] H) { | |
// write your code in Java SE 8 | |
Stack<Integer> wall=new Stack<Integer>(); | |
int blocks=0; | |
for(int index=0;index<H.length;index++){ | |
while(!wall.empty()&&H[index]<wall.peek()){ | |
wall.pop(); | |
if(!wall.empty()&&H[index]>wall.peek()){ |
This file contains hidden or 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
import java.util.Stack; | |
class Solution { | |
public int solution(int[] A, int[] B) { | |
// write your code in Java SE 8 | |
Stack<Integer> upStack=new Stack<Integer>(); | |
Stack<Integer> downStack=new Stack<Integer>(); | |
for(int index=0;index<A.length;index++){ | |
if(B[index]==0){ | |
while(!downStack.empty()&&downStack.peek()<A[index]){ |
This file contains hidden or 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
import java.util.Stack; | |
class Solution { | |
public int solution(String S) { | |
// write your code in Java SE 8 | |
Stack<String>stack=new Stack<String>(); | |
for(int index=0;index<S.length();index++){ | |
if(S.charAt(index)=='('){ | |
stack.push("("); | |
}else{ |
This file contains hidden or 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
import java.util.Stack; | |
class Solution { | |
public int solution(String S) { | |
// write your code in Java SE 8 | |
char [] test= S.toCharArray(); | |
Stack<String> container=new Stack<String>(); | |
for (int index=0;index<test.length;index++){ | |
char popped=test[index]; | |
if(container.empty()){ |