Skip to content
36 changes: 36 additions & 0 deletions Week_02/id_12/242_12
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Solution {

/**
* @param String $s
* @param String $t
* @return Boolean
*/
function isAnagram($s, $t) {
$ttemp = $t;
$sLen = strlen($s);
$tLen = strlen($t);
if($sLen != $tLen){
return false;
}
$sbool = $tbool = true;
for($i=0;$i<$sLen;$i++){
if(stripos($t, $s[$i]) === false){
$sbool = false;
break;
}
$t = preg_replace("/$s[$i]/", '', $t, 1);
}
for($j=0;$j<$tLen;$j++){
if(stripos($s, $ttemp[$j]) === false){
$tbool = false;
break;
}
$s = preg_replace("/$ttemp[$j]/", '', $s, 1);
}
if($sbool && $tbool){
return true;
}else{
return false;
}
}
}
31 changes: 31 additions & 0 deletions Week_02/id_12/671_12
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int findSecondMinimumValue(TreeNode root) {
return traversal(root,root.val);
}

private int traversal(TreeNode root,int value){
if(root == null){
return -1;
}
if(root.val > value){
return root.val;
}
int l = traversal(root.left,value);
int r = traversal(root.right,value);

if(l>=0 && r>=0){
return Math.min(l,r);
}
return Math.max(l,r);
}

}