• Oct 22, 2024 •C S
0 likes • 9 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); };
• May 11, 2025 •C S
0 likes • 7 views
https://ui.shadcn.com/create?base=base&template=vite&baseColor=stone&theme=blue&item=pagination-example
• Oct 15, 2022 •CodeCatch
0 likes • 175 views
import { useState, useEffect, useRef } from "react"; // Usage function App() { // State value and setter for our example const [count, setCount] = useState(0); // Get the previous value (was passed into hook on last render) const prevCount = usePrevious(count); // Display both current and previous count value return ( <div> <h1> Now: {count}, before: {prevCount} </h1> <button onClick={() => setCount(count + 1)}>Increment</button> </div> ); } // Hook function usePrevious(value) { // The ref object is a generic container whose current property is mutable ... // ... and can hold any value, similar to an instance property on a class const ref = useRef(); // Store current value in ref useEffect(() => { ref.current = value; }, [value]); // Only re-run if value changes // Return previous value (happens before update in useEffect above) return ref.current; }
• Nov 21, 2023 •AustinLeath
0 likes • 25 views
// Print Hello, World! console.log("Hello, World!");
0 likes • 3 views
function removeDuplicates(nums: number[]): number { nums.splice(0, nums.length, ...Array.from(new Set(nums))); return nums.length; }; console.log(removeDuplicates([1, 2, 3, 4, 5, 6]))
0 likes • 2 views
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 [] } console.log(twoSum([1, 2, 3, 4, 5], 3))