Skip to content

Commit ada324f

Browse files
add 1153
1 parent 836cbf3 commit ada324f

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,5 @@ LeetCode
472472
|1147|[Longest Chunked Palindrome Decomposition](https://leetcode.com/problems/longest-chunked-palindrome-decomposition/) | c | [c++](./src/1147-Longest-Chunked-Palindrome-Decomposition/1147.cpp) |[python](./src/1147-Longest-Chunked-Palindrome-Decomposition/1147.py)|[go](./src/1147-Longest-Chunked-Palindrome-Decomposition/1147.go)|[js](./src/1147-Longest-Chunked-Palindrome-Decomposition/1147.js)|Hard|
473473
|1150|[Check If a Number Is Majority Element in a Sorted Array](https://leetcode.com/contest/biweekly-contest-6/problems/is-a-a-majority-element/) | c | [c++](./src/1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array/1150.cpp) |[python](./src/1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array/1150.py)|[go](./src/1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array/1150.go)|[js](./src/1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array/1150.js)|Easy|
474474
|1151|[Minimum Swaps to Group All 1's Together](https://leetcode.com/contest/biweekly-contest-6/problems/minimum-swaps-to-group-all-1s-together/) | c | [c++](./src/1151-Minimum-Swaps-to-Group-All-1's-Together/1151.cpp) |[python](./src/1151-Minimum-Swaps-to-Group-All-1's-Together/1151.py)|[go](./src/1151-Minimum-Swaps-to-Group-All-1's-Together/1151.go)|[js](./src/1151-Minimum-Swaps-to-Group-All-1's-Together/1151.js)|Medium|
475-
|1152|[Analyze User Website Visit Pattern](https://leetcode.com/contest/biweekly-contest-6/problems/analyse-user-website-visit-pattern/) | c | [c++](./src/1152-Analyze-User-Website-Visit-Pattern/1152.cpp) |[python](./src/1152-Analyze-User-Website-Visit-Pattern/1152.py)|[go](./src/1152-Analyze-User-Website-Visit-Pattern/1152.go)|[js](./src/1152-Analyze-User-Website-Visit-Pattern/1152.js)|Medium|
475+
|1152|[Analyze User Website Visit Pattern](https://leetcode.com/contest/biweekly-contest-6/problems/analyse-user-website-visit-pattern/) | c | [c++](./src/1152-Analyze-User-Website-Visit-Pattern/1152.cpp) |[python](./src/1152-Analyze-User-Website-Visit-Pattern/1152.py)|[go](./src/1152-Analyze-User-Website-Visit-Pattern/1152.go)|[js](./src/1152-Analyze-User-Website-Visit-Pattern/1152.js)|Medium|
476+
|1153|[String Transforms Into Another String](https://leetcode.com/contest/biweekly-contest-6/problems/string-transforms-into-another-string/) | c | [c++](./src/1153-String-Transforms-Into-Another-String/1153.cpp) |[python](./src/1153-String-Transforms-Into-Another-String/1153.py)|[go](./src/1153-String-Transforms-Into-Another-String/1153.go)|[js](./src/1153-String-Transforms-Into-Another-String/1153.js)|Hard|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution
2+
{
3+
public:
4+
bool canConvert(string str1, string str2)
5+
{
6+
unordered_set<char> s2(str2.begin(), str2.end());
7+
if (s2.size() == 26) return str1 == str2;
8+
9+
unordered_map<char, char> d;
10+
for (int i = 0; i < str1.size(); ++i)
11+
{
12+
if (d.count(str1[i]))
13+
{
14+
if (d[str1[i]] != str2[i]) return false;
15+
}
16+
else d[str1[i]] = str2[i];
17+
}
18+
return true;
19+
}
20+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
func canConvert(str1 string, str2 string) bool {
2+
s2 := make(map[rune]int)
3+
for _, v := range str2 {
4+
s2[v]++
5+
}
6+
if len(s2) == 26 {
7+
return str1 == str2
8+
}
9+
10+
d := make(map[byte]byte)
11+
for i := 0; i < len(str1); i++ {
12+
if _, ok := d[str1[i]]; ok {
13+
if d[str1[i]] != str2[i] {
14+
return false
15+
}
16+
} else {
17+
d[str1[i]] = str2[i]
18+
}
19+
}
20+
return true
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var canConvert = function(str1, str2) {
2+
var s2 = new Set(str2);
3+
if (s2.size == 26) return str1 == str2;
4+
var d = new Map();
5+
for (var i = 0; i < str1.length; ++i) {
6+
if (d.has(str1[i])) {
7+
if (d.get(str1[i]) != str2[i]) return false;
8+
} else d.set(str1[i], str2[i]);
9+
}
10+
return true;
11+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def canConvert(self, str1: str, str2: str) -> bool:
3+
n, m = len(str1), len(set(str2))
4+
if m == 26:
5+
return str1 == str2
6+
7+
d = {}
8+
for i, c in enumerate(str1):
9+
if c in d:
10+
if d[c] != str2[i]:
11+
return False
12+
else:
13+
d[c] = str2[i]
14+
return True

0 commit comments

Comments
 (0)