Skip to main content

C S

User since Oct 28, 2022
32 Posts

Recent Posts

LeetCode - Search Insert Position

Oct 22, 2024C S

0 likes • 2 views

function binarySearch(nums: number[], target: number): number {
let left = 0;
let right = nums.length - 1;
while (left <= right) {
const mid = left + Math.floor((right - left) / 2);
if (nums[mid] === target) {
return mid;
} else if (nums[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return left;
}
function searchInsert(nums: number[], target: number): number {
return binarySearch(nums, target);
};

LeetCode - Remove Element

Oct 22, 2024C S

0 likes • 2 views

function removeElement(nums: number[], val: number): number {
let zeroStartIndex = 0;
for(let i = 0; i < nums.length; i++) {
if(nums[i] !== val) {
nums[zeroStartIndex] = nums[i];
zeroStartIndex++;
}
}
return zeroStartIndex;
};
function removeDuplicates(nums: number[]): number {
nums.splice(0, nums.length, ...Array.from(new Set(nums)));
return nums.length;
};

LeetCode - Two Sum

Oct 22, 2024C S

0 likes • 1 view

function twoSum(nums: number[], target: number): number[] {
const map = new Map();
for(let i = 0; i < nums.length; i++) {
if(map.has(target - nums[i])) {
return [map.get(target - nums[i]), i];
} else {
map.set(nums[i], i);
}
}
return []
}

Post Statistics

Posts

No Posts Found

It looks like C S has no public posts

Likes

Please Log In

You must be authenticated to view a user's likes

Shared

Please Log In

You must be authenticated to view a user's shared posts

Profile Privacy

Multi-Factor Authentication

Multi-Factor Authentication (MFA) is an authentication method that requires you to provide two or more verification factors to gain access to your account. In addition to username and password, MFA requires you to verify your email on every login, which decreases the likelihood of someone stealing your account.

Change Password

Forgot Password?

Identity Color

Changes the color of your profile icon and cursor highlight in the live code editor. You and other users will be able to view this change.

Delete Account

Deleting your account is permanent. All data associated with your account will be lost.