Last active
February 28, 2016 04:50
-
-
Save ayushjain7/0467287fecab236738ab to your computer and use it in GitHub Desktop.
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
1. maximum Difference | |
2. k-subsequence | |
3. single-line and multi-line comments | |
4. unique domains. | |
3. | |
import java.io.*; | |
public class Solution { | |
public static void main(String args[] ) throws Exception { | |
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | |
String line ; | |
int count = 0; | |
boolean multiLine = false; | |
while((line = in.readLine())!=null){ | |
int index = line.indexOf("//"); | |
if(index >= 0) | |
System.out.println(line.substring(index)); | |
else{ | |
if(multiLine){ | |
int index1 = line.indexOf("*/"); | |
if(index1 >= 0){ | |
System.out.println(line.substring(0, index1+2).trim()); | |
multiLine = false; | |
}else{ | |
System.out.println(line.trim()); | |
} | |
}else{ | |
int beginIndex = line.indexOf("/*"); | |
int endIndex = line.indexOf("*/"); | |
if(beginIndex >= 0){ | |
if(endIndex > beginIndex){ | |
System.out.println(line.substring(beginIndex, endIndex+2)); | |
} | |
else { | |
System.out.println(line.substring(beginIndex)); | |
multiLine =true; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
1. | |
/* | |
* Complete the function below. | |
*/ | |
static int maxDifference(int[] a) { | |
if(a == null || a.length <= 1) | |
return 0; | |
int maxDiff = Integer.MIN_VALUE; | |
int min = a[0]; | |
for(int i =1; i <a.length; i++){ | |
/*for(int j = i+1; j<a.length; j++){ | |
if(max < a[j]-a[i]){ | |
max = a[j]-a[i]; | |
} | |
}*/ | |
if(a[i]-min > maxDiff) | |
maxDiff = a[i]-min; | |
min = Math.min(min, a[i]); | |
} | |
return maxDiff; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regex Matching on URLs