-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
996bc1d
commit 6760527
Showing
19 changed files
with
95 additions
and
66 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
src/page-17/1822. Sign of the Product of an Array/array-sign.ts
This file was deleted.
Oops, something went wrong.
8 changes: 1 addition & 7 deletions
8
...he Product of an Array/array-sign.test.ts → ...the Product of an Array/arraySign.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import { arraySign, arraySign2 } from './array-sign'; | ||
import { arraySign } from './arraySign'; | ||
|
||
describe('1822. Sign of the Product of an Array', () => { | ||
test('arraySign', () => { | ||
expect(arraySign([-1, -2, -3, -4, 3, 2, 1])).toBe(1); | ||
expect(arraySign([1, 5, 0, 2, -3])).toBe(0); | ||
expect(arraySign([-1, 1, -1, 1, -1])).toBe(-1); | ||
}); | ||
|
||
test('arraySign2', () => { | ||
expect(arraySign2([-1, -2, -3, -4, 3, 2, 1])).toBe(1); | ||
expect(arraySign2([1, 5, 0, 2, -3])).toBe(0); | ||
expect(arraySign2([-1, 1, -1, 1, -1])).toBe(-1); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
src/page-17/1822. Sign of the Product of an Array/arraySign.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type ArraySign = (nums: number[]) => number; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const arraySign: ArraySign = (nums) => { | ||
let result = 1; | ||
|
||
for (const num of nums) { | ||
if (num === 0) return 0; | ||
if (num < 0) result *= -1; | ||
} | ||
|
||
return result; | ||
}; |
16 changes: 0 additions & 16 deletions
16
src/page-17/1827. Minimum Operations to Make the Array Increasing/min-operations.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...e Array Increasing/min-operations.test.ts → ...he Array Increasing/minOperations.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/page-17/1827. Minimum Operations to Make the Array Increasing/minOperations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type MinOperations = (nums: number[]) => number; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const minOperations: MinOperations = (nums) => { | ||
let operations = 0; | ||
|
||
for (let i = 1; i < nums.length; i++) { | ||
if (nums[i] <= nums[i - 1]) { | ||
const neededIncrement = nums[i - 1] - nums[i] + 1; | ||
nums[i] += neededIncrement; | ||
operations += neededIncrement; | ||
} | ||
} | ||
|
||
return operations; | ||
}; |
2 changes: 1 addition & 1 deletion
2
...tence Is Pangram/check-if-pangram.test.ts → ...entence Is Pangram/checkIfPangram.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...e Sentence Is Pangram/check-if-pangram.ts → ...the Sentence Is Pangram/checkIfPangram.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
type CheckIfPangram = (sentence: string) => boolean; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const checkIfPangram: CheckIfPangram = (sentence) => { | ||
return new Set([...sentence]).size === 26; | ||
}; |
This file was deleted.
Oops, something went wrong.
7 changes: 6 additions & 1 deletion
7
... Sum of Digits in Base K/sum-base.test.ts → .... Sum of Digits in Base K/sumBase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { sumBase } from './sum-base'; | ||
import { sumBase, sumBase2 } from './sumBase'; | ||
|
||
describe('1837. Sum of Digits in Base K', () => { | ||
test('sumBase', () => { | ||
expect(sumBase(34, 6)).toBe(9); | ||
expect(sumBase(10, 10)).toBe(1); | ||
}); | ||
|
||
test('sumBase2', () => { | ||
expect(sumBase2(34, 6)).toBe(9); | ||
expect(sumBase2(10, 10)).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
type SumBase = (n: number, k: number) => number; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const sumBase: SumBase = (n, k) => { | ||
return n | ||
.toString(k) | ||
.split('') | ||
.map((val) => Number(val)) | ||
.reduce((acc, cur) => acc + cur); | ||
}; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const sumBase2: SumBase = (n, k) => { | ||
let sum = 0; | ||
let current = n; | ||
|
||
// Convert n to base k | ||
while (current > 0) { | ||
sum += current % k; // Add the current digit to the sum | ||
current = Math.floor(current / k); // Update current by integer division | ||
} | ||
|
||
return sum; | ||
}; |
2 changes: 1 addition & 1 deletion
2
...ts with Characters/replace-digits.test.ts → ...its with Characters/replaceDigits.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
... Digits with Characters/replace-digits.ts → ...l Digits with Characters/replaceDigits.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...e Target Element/get-min-distance.test.ts → ...the Target Element/getMinDistance.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...to the Target Element/get-min-distance.ts → ...e to the Target Element/getMinDistance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
type GetMinDistance = (nums: number[], target: number, start: number) => number; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const getMinDistance: GetMinDistance = (nums, target, start) => { | ||
let result = Number.POSITIVE_INFINITY; | ||
let minDiff = Number.POSITIVE_INFINITY; | ||
|
||
for (let i = 0; i < nums.length; i++) { | ||
if (nums[i] === target) { | ||
result = Math.min(result, Math.abs(i - start)); | ||
minDiff = Math.min(minDiff, Math.abs(i - start)); | ||
} | ||
} | ||
|
||
return result; | ||
return minDiff; | ||
}; |
2 changes: 1 addition & 1 deletion
2
...opulation Year/maximum-population.test.ts → ...Population Year/maximumPopulation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...mum Population Year/maximum-population.ts → ...imum Population Year/maximumPopulation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...orting the Sentence/sort-sentence.test.ts → ...Sorting the Sentence/sortSentence.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
...59. Sorting the Sentence/sort-sentence.ts → ...859. Sorting the Sentence/sortSentence.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
type SortSentence = (s: string) => string; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const sortSentence: SortSentence = (s) => { | ||
return s | ||
.split(' ') | ||
.sort((a, b) => Number(a.charAt(a.length - 1)) - Number(b.charAt(b.length - 1))) | ||
.map((word) => word.slice(0, word.length - 1)) | ||
.sort((a, b) => Number(a[a.length - 1]) - Number(b[b.length - 1])) | ||
.map((word) => word.slice(0, -1)) | ||
.join(' '); | ||
}; |