waledsalah2005
BAN USER// Here is my Code
static int[][] grid; // global array
public static long max(int r , int c,int R,int C)
{
if(r<0||r>R-1||c<0||c>C-1)return Long.MIN_VALUE;
if(r==R-1&&c==C-1)return grid[r][c];
long path1 =max(r,c+1,R,C);
long path2=max(r+1,c,R,C);
return grid[r][c]+Math.max(path1, path2);
}
// In Main Method
// Initialize 2D grid
// call method max(0,0,n,n)
public static String dup(String word)
{
boolean check =false; //"";
HashSet<Character>s = new HashSet<Character>();
String result = "";
for(int i = 0 ; i < word.length();++i)
{
check =s.add(word.charAt(i));
if(word.charAt(i)>='a'&&word.charAt(i)<='z')
{
char ch = (char)((char)word.charAt(i)-'a'+'A');
check =s.add(ch);
if(check==true)
{
result += word.charAt(i);
}
}
else if(word.charAt(i)>='A'&&word.charAt(i)<='Z')
{
char ch = (char)((char)word.charAt(i)-'A'+'a');
check =s.add(ch);
if(check==true)
{
result += word.charAt(i);
}
}
else
{
if(check==true)
{
result += word.charAt(i);
}
}
}
return result;
}
public static String dup(String word)
{
boolean check =false; //"";
HashSet<Character>s = new HashSet<Character>();
String result = "";
for(int i = 0 ; i < word.length();++i)
{
check =s.add(word.charAt(i));
if(word.charAt(i)>='a'&&word.charAt(i)<='z')
{
char ch = (char)((char)word.charAt(i)-'a'+'A');
check =s.add(ch);
if(check==true)
{
result += word.charAt(i);
}
}
else if(word.charAt(i)>='A'&&word.charAt(i)<='Z')
{
char ch = (char)((char)word.charAt(i)-'A'+'a');
check =s.add(ch);
if(check==true)
{
result += word.charAt(i);
}
}
else
{
if(check==true)
{
result += word.charAt(i);
}
}
}
return result;
}
java code
public static String dup(String word)
{
boolean check =false; //"";
HashSet<Character>s = new HashSet<Character>();
String result = "";
for(int i = 0 ; i < word.length();++i)
{
check =s.add(word.charAt(i));
if(word.charAt(i)>='a'&&word.charAt(i)<='z')
{
char ch = (char)((char)word.charAt(i)-'a'+'A');
check =s.add(ch);
if(check==true)
{
result += word.charAt(i);
}
}
else if(word.charAt(i)>='A'&&word.charAt(i)<='Z')
{
char ch = (char)((char)word.charAt(i)-'A'+'a');
check =s.add(ch);
if(check==true)
{
result += word.charAt(i);
}
}
else
{
if(check==true)
{
result += word.charAt(i);
}
}
}
return result;
my code is up (anonymous)
and it is modified
public String dup(String word)
{
boolean check =false; //"";
HashSet<Character>s = new HashSet<Character>();
String result = "";
for(int i = 0 ; i < word.length();++i)
{
check =s.add(word.charAt(i));
if(check==true)
{
result += word.charAt(i);
}
}
return result;
}
I know how to optimize this cood , i wrote simple code :)
- waledsalah2005 August 31, 2014thx