purpleshoes
BAN USER
Good & simple.
- purpleshoes November 30, 2014I like this solution. Very simple and O(n) time and O(1) space.
- purpleshoes November 30, 2014Good & simple.
- purpleshoes November 30, 2014public class MaxLengthPalindrome {
public static int[] a= {4,12,3,4,5,6,4,3,4,4,4,4,4,4,4};
public static int maxLength(int i, int j) {
if (Math.abs(i-j)==1 || Math.abs(i-j)==0) return a[i]==a[j]?2:1;
System.out.println(i + " " + j);
if (a[i]==a[j])
return 2+maxLength(i+1,j-1);
return Math.max(maxLength(i+1,j), maxLength(i,j-1));
}
public static void main(String[] args) {
System.out.println(maxLength(0,a.length-1));
}
}
public class MaxLengthPalindrome {
public static int[] a= {4,12,3,4,5,6,4,3,4,4,4,4,4,4,4};
public static int maxLength(int i, int j) {
if (Math.abs(i-j)==1 || Math.abs(i-j)==0) return a[i]==a[j]?2:1;
System.out.println(i + " " + j);
if (a[i]==a[j])
return 2+maxLength(i+1,j-1);
return Math.max(maxLength(i+1,j), maxLength(i,j-1));
}
public static void main(String[] args) {
System.out.println(maxLength(0,a.length-1));
}
}
import java.util.Arrays;
public class TriangleTriplets {
//note: you don't need to check the other two cases since the array is sorted.
public static boolean check(int a, int b, int c) {
return (a+b>c);
}
public static void triangleTriples(int[] a) {
for (int i = 0; i<a.length; i++) {
for (int j = i+1; j<a.length; j++) {
for (int k = j+1; k<a.length; k++) {
if (check(a[i],a[j],a[k]))
System.out.println(a[i] + " " + a[j] + " " + a[k]);
}
}
}
}
public static void main(String[] args) {
int[] a = {7,8,9,10};
Arrays.sort(a);
triangleTriples(a);
}
}
What is k initialized as? And don't you need to make sure a[k] is not the same as a[i] or a[j]?
- purpleshoes November 29, 2014Can you be more specific?
- purpleshoes November 29, 2014
Can you explain what your'e doing?
- purpleshoes December 01, 2014