Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.1k
feat: add solutions to lc problems: No.3550,3551#4411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
feat: add solutions to lc problems: No.3550,3551
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit427f79b6a70a4cc3c7375b49eea27ae0d491a8cc
There are no files selected for viewing
78 changes: 74 additions & 4 deletionssolution/3500-3599/3550.Smallest Index With Digit Sum Equal to Index/README.md
This file contains hidden or 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
78 changes: 74 additions & 4 deletionssolution/3500-3599/3550.Smallest Index With Digit Sum Equal to Index/README_EN.md
This file contains hidden or 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
16 changes: 16 additions & 0 deletionssolution/3500-3599/3550.Smallest Index With Digit Sum Equal to Index/Solution.cpp
This file contains hidden or 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,16 @@ | ||
classSolution { | ||
public: | ||
intsmallestIndex(vector<int>& nums) { | ||
for (int i =0; i < nums.size(); ++i) { | ||
int s =0; | ||
while (nums[i]) { | ||
s += nums[i] %10; | ||
nums[i] /=10; | ||
} | ||
if (s == i) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
}; |
12 changes: 12 additions & 0 deletionssolution/3500-3599/3550.Smallest Index With Digit Sum Equal to Index/Solution.go
This file contains hidden or 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,12 @@ | ||
funcsmallestIndex(nums []int)int { | ||
fori,x:=rangenums { | ||
s:=0 | ||
for ;x>0;x/=10 { | ||
s+=x%10 | ||
} | ||
ifs==i { | ||
returni | ||
} | ||
} | ||
return-1 | ||
} |
15 changes: 15 additions & 0 deletionssolution/3500-3599/3550.Smallest Index With Digit Sum Equal to Index/Solution.java
This file contains hidden or 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 @@ | ||
classSolution { | ||
publicintsmallestIndex(int[]nums) { | ||
for (inti =0;i <nums.length; ++i) { | ||
ints =0; | ||
while (nums[i] !=0) { | ||
s +=nums[i] %10; | ||
nums[i] /=10; | ||
} | ||
if (s ==i) { | ||
returni; | ||
} | ||
} | ||
return -1; | ||
} | ||
} |
10 changes: 10 additions & 0 deletionssolution/3500-3599/3550.Smallest Index With Digit Sum Equal to Index/Solution.py
This file contains hidden or 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,10 @@ | ||
classSolution: | ||
defsmallestIndex(self,nums:List[int])->int: | ||
fori,xinenumerate(nums): | ||
s=0 | ||
whilex: | ||
s+=x%10 | ||
x//=10 | ||
ifs==i: | ||
returni | ||
return-1 |
12 changes: 12 additions & 0 deletionssolution/3500-3599/3550.Smallest Index With Digit Sum Equal to Index/Solution.ts
This file contains hidden or 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,12 @@ | ||
functionsmallestIndex(nums:number[]):number{ | ||
for(leti=0;i<nums.length;++i){ | ||
lets=0; | ||
for(;nums[i]>0;nums[i]=Math.floor(nums[i]/10)){ | ||
s+=nums[i]%10; | ||
} | ||
if(s===i){ | ||
returni; | ||
} | ||
} | ||
return-1; | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.