diff --git a/HamSungJun/Solution_1518.ts b/HamSungJun/Solution_1518.ts new file mode 100644 index 0000000..f387366 --- /dev/null +++ b/HamSungJun/Solution_1518.ts @@ -0,0 +1,8 @@ +function restoreString (s: string, indices: number[]): string { + const strArray: string[] = new Array(s.length) + for (let i = 0; i < indices.length; i++) { + const nextIdx = indices[i] + strArray[nextIdx] = s[i] + } + return strArray.join('') +}; diff --git a/HamSungJun/Solution_1603.ts b/HamSungJun/Solution_1603.ts new file mode 100644 index 0000000..084c399 --- /dev/null +++ b/HamSungJun/Solution_1603.ts @@ -0,0 +1,24 @@ +class ParkingSystem { + carSlots = new Array(3).fill(0) + constructor (big: number, medium: number, small: number) { + this.carSlots[0] = big + this.carSlots[1] = medium + this.carSlots[2] = small + } + + addCar (carType: number): boolean { + const nextSlot = carType - 1 + if (this.carSlots[nextSlot] === 0) { + return false + } else { + this.carSlots[nextSlot] -= 1 + return true + } + } +} + +/** + * Your ParkingSystem object will be instantiated and called as such: + * var obj = new ParkingSystem(big, medium, small) + * var param_1 = obj.addCar(carType) + */ diff --git a/HamSungJun/Solution_1913.ts b/HamSungJun/Solution_1913.ts new file mode 100644 index 0000000..9b4ec03 --- /dev/null +++ b/HamSungJun/Solution_1913.ts @@ -0,0 +1,6 @@ +function maxProductDifference (nums: number[]): number { + nums.sort((a, b) => { + return Number(a > b) - Number(a < b) + }) + return (nums[nums.length - 1] * nums[nums.length - 2]) - (nums[0] * nums[1]) +};