Movatterモバイル変換


[0]ホーム

URL:


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

Commit1532204

Browse files
committed
add new files
1 parenta54b1a5 commit1532204

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

‎1185. Day of the Week.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
Given a date, return the corresponding day of the week for that date.
3+
4+
The input is given as three integers representing the day, month and year respectively.
5+
6+
Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.
7+
8+
9+
10+
Example 1:
11+
12+
Input: day = 31, month = 8, year = 2019
13+
Output: "Saturday"
14+
Example 2:
15+
16+
Input: day = 18, month = 7, year = 1999
17+
Output: "Sunday"
18+
19+
*/
20+
package main
21+
22+
import (
23+
"fmt"
24+
"time"
25+
)
26+
27+
funcdayOfTheWeek(dayint,monthint,yearint)string {
28+
t:=time.Date(year,time.Month(month),day,0,0,0,0,time.UTC)
29+
returnt.Weekday().String()
30+
}
31+
32+
funcmain() {
33+
str:=dayOfTheWeek(31,8,2019)
34+
fmt.Println(str)
35+
}
36+
37+
/**
38+
note:use golang intern function
39+
*/

‎1207. Unique Number of Occurrences.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique.
3+
4+
5+
6+
Example 1:
7+
8+
Input: arr = [1,2,2,1,1,3]
9+
Output: true
10+
Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
11+
Example 2:
12+
13+
Input: arr = [1,2]
14+
Output: false
15+
16+
*/
17+
package main
18+
19+
funcuniqueOccurrences(arr []int)bool {
20+
counts:=make(map[int]int)
21+
for_,i:=rangearr {
22+
counts[i]+=1
23+
}
24+
set:=make(map[int]bool)
25+
for_,c:=rangecounts {
26+
if_,ok:=set[c];ok {
27+
returnfalse
28+
}
29+
set[c]=true
30+
}
31+
returntrue
32+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
Balanced strings are those who have equal quantity of 'L' and 'R' characters.
3+
4+
Given a balanced string s split it in the maximum amount of balanced strings.
5+
6+
Return the maximum amount of splitted balanced strings.
7+
8+
9+
10+
Example 1:
11+
12+
Input: s = "RLRRLLRLRL"
13+
Output: 4
14+
Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.
15+
Example 2:
16+
17+
Input: s = "RLLLLRRRLR"
18+
Output: 3
19+
Explanation: s can be split into "RL", "LLLRRR", "LR", each substring contains same number of 'L' and 'R'.
20+
21+
*/
22+
package main
23+
24+
funcbalancedStringSplit(sstring)int {
25+
varsum,resint
26+
for_,c:=ranges {
27+
ifc=='R' {
28+
sum+=1
29+
}else {
30+
sum-=1
31+
}
32+
ifsum==0 {
33+
res+=1
34+
}
35+
}
36+
returnres
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp