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

Commitf9b9b6c

Browse files
authored
Merge branch 'master' into sambabib-js-solutions
2 parentsb7dc87f +efa91d4 commitf9b9b6c

File tree

50 files changed

+1876
-601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1876
-601
lines changed

‎cpp/_916.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
classSolution {
2+
public:
3+
vector<string>wordSubsets(vector<string>& words1, vector<string>& words2) {
4+
int maxCharFreq[26] = {0};
5+
int tempCharFreq[26];
6+
for (constauto& word : words2) {
7+
memset(tempCharFreq,0,sizeof tempCharFreq);
8+
for (char ch : word) {
9+
tempCharFreq[ch -'a']++;
10+
}
11+
for (int i =0; i <26; ++i) {
12+
maxCharFreq[i] =max(maxCharFreq[i], tempCharFreq[i]);
13+
}
14+
}
15+
vector<string> universalWords;
16+
for (constauto& word : words1) {
17+
memset(tempCharFreq,0,sizeof tempCharFreq);
18+
for (char ch : word) {
19+
tempCharFreq[ch -'a']++;
20+
}
21+
bool isUniversal =true;
22+
for (int i =0; i <26; ++i) {
23+
if (maxCharFreq[i] > tempCharFreq[i]) {
24+
isUniversal =false;
25+
break;
26+
}
27+
}
28+
if (isUniversal) {
29+
universalWords.emplace_back(word);
30+
}
31+
}
32+
return universalWords;
33+
}
34+
};

‎paginated_contents/algorithms/2nd_thousand/README.md

Lines changed: 275 additions & 274 deletions
Large diffs are not rendered by default.

‎paginated_contents/algorithms/3rd_thousand/README.md

Lines changed: 284 additions & 283 deletions
Large diffs are not rendered by default.

‎paginated_contents/algorithms/4th_thousand/README.md

Lines changed: 72 additions & 41 deletions
Large diffs are not rendered by default.

‎paginated_contents/database/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| 3059|[Find All Unique Email Domains](https://leetcode.com/problems/find-all-unique-email-domains/)|[Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_3159.sql)|| Easy|
77
| 3051|[Find Candidates for Data Scientist Position](https://leetcode.com/problems/find-candidates-for-data-scientist-position/)|[Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_3051.sql)|| Easy|
88
| 2990|[Loan Types](https://leetcode.com/problems/loan-types/)|[Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_2990.sql)|| Easy|
9+
| 2879|[Display the First Three Rows](https://leetcode.com/problems/display-the-first-three-rows/)|[Python3](https://github.com/fishercoder1534/Leetcode/blob/master/python3/2879.py)|| Easy|
910
| 2205|[The Number of Users That Are Eligible for Discount](https://leetcode.com/problems/the-number-of-users-that-are-eligible-for-discount/)|[Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_2205.sql)|| Easy|
1011
| 2082|[The Number of Rich Customers](https://leetcode.com/problems/the-number-of-rich-customers/)|[Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_2082.sql)|| Easy|
1112
| 2072|[The Winner University](https://leetcode.com/problems/the-winner-university/)|[Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_2072.sql)|| Easy|

‎python3/2879.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
importpandasaspd
2+
3+
defselectFirstRows(employees:pd.DataFrame)->pd.DataFrame:
4+
returnemployees.head(3)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
publicclass_3270 {
4+
publicstaticclassSolution1 {
5+
publicintgenerateKey(intnum1,intnum2,intnum3) {
6+
String[]padded =newString[3];
7+
padded[0] =String.format("%04d",num1);
8+
padded[1] =String.format("%04d",num2);
9+
padded[2] =String.format("%04d",num3);
10+
StringBuildersb =newStringBuilder();
11+
for (inti =0;i <padded[0].length();i++) {
12+
sb.append(
13+
Math.min(
14+
Character.getNumericValue(padded[0].charAt(i)),
15+
Math.min(
16+
Character.getNumericValue(padded[1].charAt(i)),
17+
Character.getNumericValue(padded[2].charAt(i)))));
18+
}
19+
returnInteger.parseInt(sb.toString());
20+
}
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.HashSet;
4+
importjava.util.Set;
5+
6+
publicclass_3274 {
7+
publicstaticclassSolution1 {
8+
publicbooleancheckTwoChessboards(Stringcoordinate1,Stringcoordinate2) {
9+
returnisBlack(coordinate2) ==isBlack(coordinate1);
10+
}
11+
12+
privatebooleanisBlack(Stringcoordinate) {
13+
Set<Character>blackColsWithOddRows =newHashSet<>();
14+
blackColsWithOddRows.add('a');
15+
blackColsWithOddRows.add('c');
16+
blackColsWithOddRows.add('e');
17+
blackColsWithOddRows.add('g');
18+
if (blackColsWithOddRows.contains(coordinate.charAt(0))) {
19+
returnCharacter.getNumericValue(coordinate.charAt(1)) %2 ==1;
20+
}else {
21+
returnCharacter.getNumericValue(coordinate.charAt(1)) %2 ==0;
22+
}
23+
}
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
publicclass_3280 {
4+
publicstaticclassSolution1 {
5+
publicStringconvertDateToBinary(Stringdate) {
6+
String[]parts =date.split("-");
7+
StringBuildersb =newStringBuilder();
8+
for (Stringpart :parts) {
9+
sb.append(Integer.toBinaryString(Integer.parseInt(part)));
10+
sb.append("-");
11+
}
12+
sb.setLength(sb.length() -1);
13+
returnsb.toString();
14+
}
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.List;
5+
6+
publicclass_3285 {
7+
publicstaticclassSolution1 {
8+
publicList<Integer>stableMountains(int[]height,intthreshold) {
9+
List<Integer>ans =newArrayList<>();
10+
for (inti =1;i <height.length;i++) {
11+
if (height[i -1] >threshold) {
12+
ans.add(i);
13+
}
14+
}
15+
returnans;
16+
}
17+
}
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.HashSet;
4+
importjava.util.Set;
5+
6+
publicclass_3289 {
7+
publicstaticclassSolution1 {
8+
publicint[]getSneakyNumbers(int[]nums) {
9+
int[]ans =newint[2];
10+
Set<Integer>set =newHashSet<>();
11+
inti =0;
12+
for (intnum :nums) {
13+
if (!set.add(num)) {
14+
ans[i++] =num;
15+
}
16+
}
17+
returnans;
18+
}
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
publicclass_3300 {
4+
publicstaticclassSolution1 {
5+
publicintminElement(int[]nums) {
6+
intmin =Integer.MAX_VALUE;
7+
for (intnum :nums) {
8+
min =Math.min(min,findSum(num));
9+
}
10+
returnmin;
11+
}
12+
13+
privateintfindSum(intnum) {
14+
intsum =0;
15+
while (num !=0) {
16+
sum +=num %10;
17+
num /=10;
18+
}
19+
returnsum;
20+
}
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
publicclass_3304 {
4+
publicstaticclassSolution1 {
5+
publiccharkthCharacter(intk) {
6+
StringBuildersb =newStringBuilder("a");
7+
while (sb.length() <=k) {
8+
intn =sb.length();
9+
for (inti =0;i <n;i++) {
10+
sb.append((char) (sb.charAt(i) +1));
11+
}
12+
}
13+
returnsb.charAt(k -1);
14+
}
15+
}
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.List;
4+
5+
publicclass_3314 {
6+
publicstaticclassSolution1 {
7+
publicint[]minBitwiseArray(List<Integer>nums) {
8+
int[]ans =newint[nums.size()];
9+
for (inti =0;i <nums.size();i++) {
10+
booleanfound =false;
11+
for (intj =1;j <nums.get(i);j++) {
12+
if ((j | (j +1)) ==nums.get(i)) {
13+
ans[i] =j;
14+
found =true;
15+
break;
16+
}
17+
}
18+
if (!found) {
19+
ans[i] = -1;
20+
}
21+
}
22+
returnans;
23+
}
24+
}
25+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
importjava.util.PriorityQueue;
6+
7+
publicclass_3318 {
8+
publicstaticclassSolution1 {
9+
publicint[]findXSum(int[]nums,intk,intx) {
10+
PriorityQueue<int[]>maxHeap =
11+
newPriorityQueue<>(
12+
(a,b) ->
13+
a[1] !=b[1]
14+
?b[1] -a[1]
15+
:b[0] -a[0]);// a[0] is the number itself, a[1]
16+
// is the frequency
17+
Map<Integer,int[]>map =newHashMap<>();
18+
inti =0;
19+
for (;i <k;i++) {
20+
int[]a =map.getOrDefault(nums[i],newint[2]);
21+
a[0] =nums[i];
22+
a[1]++;
23+
map.put(nums[i],a);
24+
}
25+
maxHeap.addAll(map.values());
26+
int[]ans =newint[nums.length -k +1];
27+
for (intj =i -1,p =0;j <nums.length; ) {
28+
ans[p++] =computeTopX(newPriorityQueue<>(maxHeap),x);
29+
30+
j++;
31+
if (j >=nums.length) {
32+
break;
33+
}
34+
int[]a =map.getOrDefault(nums[j],newint[2]);
35+
a[0] =nums[j];
36+
a[1]++;
37+
map.put(nums[j],a);
38+
39+
a =map.getOrDefault(nums[j -k],newint[2]);
40+
a[0] =nums[j -k];
41+
a[1]--;
42+
map.put(nums[j -k],a);
43+
44+
maxHeap.clear();
45+
maxHeap.addAll(map.values());
46+
}
47+
returnans;
48+
}
49+
50+
privateintcomputeTopX(PriorityQueue<int[]>maxHeap,intx) {
51+
intsum =0;
52+
while (!maxHeap.isEmpty() &&x-- >0) {
53+
int[]a =maxHeap.poll();
54+
sum +=a[0] *a[1];
55+
}
56+
returnsum;
57+
}
58+
}
59+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.List;
5+
6+
publicclass_3324 {
7+
publicstaticclassSolution1 {
8+
publicList<String>stringSequence(Stringtarget) {
9+
List<String>ans =newArrayList<>();
10+
StringBuildersb =newStringBuilder();
11+
for (charc :target.toCharArray()) {
12+
charcandidate ='a';
13+
booleanfirstTime =true;
14+
do {
15+
if (firstTime) {
16+
firstTime =false;
17+
sb.append(candidate);
18+
}else {
19+
sb.setLength(sb.length() -1);
20+
candidate = (char) (candidate +1);
21+
sb.append(candidate);
22+
}
23+
ans.add(sb.toString());
24+
}while (c !=candidate);
25+
}
26+
returnans;
27+
}
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
publicclass_3330 {
4+
publicstaticclassSolution1 {
5+
publicintpossibleStringCount(Stringword) {
6+
intans =1;
7+
for (inti =1;i <word.length();i++) {
8+
if (word.charAt(i) ==word.charAt(i -1)) {
9+
ans++;
10+
}
11+
}
12+
returnans;
13+
}
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
publicclass_3340 {
4+
publicstaticclassSolution1 {
5+
publicbooleanisBalanced(Stringnum) {
6+
intoddSum =0;
7+
intevenSum =0;
8+
for (inti =0;i <num.length();i++) {
9+
if (i %2 ==0) {
10+
evenSum +=Character.getNumericValue(num.charAt(i));
11+
}else {
12+
oddSum +=Character.getNumericValue(num.charAt(i));
13+
}
14+
}
15+
returnoddSum ==evenSum;
16+
}
17+
}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
publicclass_3345 {
4+
publicstaticclassSolution1 {
5+
publicintsmallestNumber(intn,intt) {
6+
for (intnum =n; ;num++) {
7+
intdigitSum =getDigitsProduct(num);
8+
if (digitSum %t ==0) {
9+
returnnum;
10+
}
11+
}
12+
}
13+
14+
privateintgetDigitsProduct(intnum) {
15+
intcopy =num;
16+
intproduct =1;
17+
while (copy !=0) {
18+
product *=copy %10;
19+
copy /=10;
20+
}
21+
returnproduct;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp