Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4f573c

Browse files
committed
change file location and add day-six
1 parent 590e7a8 commit d4f573c

File tree

8 files changed

+38
-9
lines changed

8 files changed

+38
-9
lines changed

‎README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# LeetCode Challenge
22

33
- May
4-
- Day 1: [First Bad Version](https://github.com/libterty/leetcode-challenge/blob/master/src/day-one/index.ts) :unamused:
5-
- Day 2: [Jewels and Stones](https://github.com/libterty/leetcode-challenge/blob/master/src/day-two/index.ts) :expressionless:
6-
- Day 3: [Ransom Note](https://github.com/libterty/leetcode-challenge/blob/master/src/day-three/index.ts) :hushed:
7-
- Day 4: [Number Complement](https://github.com/libterty/leetcode-challenge/blob/master/src/day-four/index.ts) :laughing:
8-
- Day 5: [First Unique Character in a String](https://github.com/libterty/leetcode-challenge/blob/master/src/day-five/index.ts) :smirk:
4+
- Day 1: [First Bad Version](https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-one/index.ts) :unamused:
5+
- Day 2: [Jewels and Stones](https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-two/index.ts) :expressionless:
6+
- Day 3: [Ransom Note](https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-three/index.ts) :hushed:
7+
- Day 4: [Number Complement](https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-four/index.ts) :laughing:
8+
- Day 5: [First Unique Character in a String](https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-five/index.ts) :smirk:
9+
- Day 6: [First Unique Character in a String](https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-six/index.ts) :relaxed:

‎src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
export * from './day-one/index';
2-
export * from './day-two/index';
3-
export * from './day-three/index';
1+
export * from './may/day-one/index';
2+
export * from './may/day-two/index';
3+
export * from './may/day-three/index';
4+
export * from './may/day-four/index';
5+
export * from './may/day-five/index';
6+
export * from './may/day-six/index';

‎src/day-five/index.ts renamed to ‎src/may/day-five/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface MapObject {
77
[key: string]: number;
88
}
99

10-
var firstUniqChar = function (s: string): number {
10+
exportconst firstUniqChar = function (s: string): number {
1111
const stringToArr: string[] = s.split('');
1212

1313
const map: MapObject = stringToArr.reduce((allChar: MapObject, char: string) => {
File renamed without changes.
File renamed without changes.

‎src/may/day-six/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
interface MapObject {
6+
[key: string]: number;
7+
}
8+
9+
export const majorityElement = function (nums: number[]): number {
10+
const toStrMap: MapObject = nums
11+
.map((i) => i.toString())
12+
.reduce((allChar: MapObject, char: string) => {
13+
if (char in allChar) {
14+
allChar[char]++;
15+
} else {
16+
allChar[char] = 1;
17+
}
18+
return allChar;
19+
}, {});
20+
21+
const strToArr: [string, number][] = Object.entries(toStrMap).sort((a, b) => b[1] - a[1]);
22+
return Number(strToArr[0][0]);
23+
};
24+
25+
majorityElement([1, 2, 3, 1]);
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /