Open Choozii opened 1 year ago
https://leetcode.com/problems/sum-of-two-integers/ /**
@return {number} */ var getSum = function(a, b) {
while(b){ let carry = a & b;
a = a ^ b;
b = carry << 1;
}
return a; };
https://leetcode.com/problems/same-tree/ /**
@return {boolean} */ var isSameTree = function(p, q) { if(!p && !q){ return true; }
const queue_p = [p]; const queue_q = [q];
while(queue_p.length || queue_q.length){ const now_p = queue_p.pop(); const now_q = queue_q.pop();
if(now_p?.val !== now_q?.val){
return false;
}else{
if(now_p.left || now_q.left){
if(now_p.left && now_q.left){
queue_p.push(now_p.left);
queue_q.push(now_q.left);
}else{
return false;
}
}
if(now_p.right || now_q.right){
if(now_p.right && now_q.right){
queue_p.push(now_p.right);
queue_q.push(now_q.right);
}else{
return false;
}
}
}
}
return true; };
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
/**
@return {number} */ var findMin = function(nums) { let left = 0, right = nums.length-1;
if(nums.length === 1){ return nums[0]; }
while(left < right){ const mid = Math.floor((left + right)/2); if(nums[mid] > nums[right]){ left = mid+1; }else{ right = mid; } }
return nums[left]; };