# 299. Bulls and Cows

``````class Solution {
public String getHint(String secret, String guess) {
int bulls = 0;
int cows = 0;
char[] chars1 = secret.toCharArray();
char[] chars2 = guess.toCharArray();
Map<Character,Integer> map1 = new HashMap<Character,Integer>();
Map<Character,Integer> map2 = new HashMap<Character,Integer>();
for(int i = 0;i<chars1.length;i++){
if(chars1[i] == chars2[I]){
bulls++;
}
else{
if(map1.containsKey(chars1[I]))
map1.put(chars1[i],map1.get(chars1[i])+1);
else
map1.put(chars1[i],1);
if(map2.containsKey(chars2[I]))
map2.put(chars2[i],map2.get(chars2[i])+1);
else
map2.put(chars2[i],1);
}
}
for(char chr:map1.keySet())
if(map2.containsKey(chr)){
cows += Math.min(map1.get(chr),map2.get(chr));
}

return bulls +"A" + cows + "B";
}
}
``````

# 300. Longest Increasing Subsequence

image.png

``````class Solution {
public int lengthOfLIS(int[] nums) {
if(nums==null || nums.length==0)
return 0;
int[] dp = new int[nums.length];
dp[0] = 1;
int res = 1;
for(int i =1;i<nums.length;i++){
int temp = 1;
for(int j=0;j<i;j++){
if(nums[i] > nums[j]){
temp = Math.max(dp[j]+1,temp);
}
}
dp[i] = temp;
res = Math.max(res,dp[i]);
}
return res;
}
}
``````

``````class Solution {
public int lengthOfLIS(int[] nums) {
int[] dp = new int[nums.length];
int len = 0;
for (int num : nums) {
int i = Arrays.binarySearch(dp, 0, len, num);
if (i < 0) {
i = -(i + 1);
}
dp[i] = num;
if (i == len) {
len++;
}
}
return len;
}
}
``````