Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Solved-Problems/Two_Sum/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import java.util.*;

Check warning on line 1 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 Using the '.*' form of import should be avoided - java.util.*. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:1:17: warning: Using the '.*' form of import should be avoided - java.util.*. (com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good practice to use only imports that are necessary.

Suggested change
import java.util.*;
import java.util.HashMap;
import java.util.Map;


class Solution {
public int[] twoSum(int[] nums, int target) {

Check warning on line 4 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'method def modifier' has incorrect indentation level 4, expected level should be 2. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:4:5: warning: 'method def modifier' has incorrect indentation level 4, expected level should be 2. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
Map<Integer, Integer> map = new HashMap<>();

Check warning on line 5 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'method def' child has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:5:9: warning: 'method def' child has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
for (int i = 0; i < nums.length; i++) {

Check warning on line 6 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'for' has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:6:9: warning: 'for' has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
int complement = target - nums[i];

Check warning on line 7 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'for' child has incorrect indentation level 12, expected level should be 6. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:7:13: warning: 'for' child has incorrect indentation level 12, expected level should be 6. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
if (map.containsKey(complement)) {

Check warning on line 8 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'if' has incorrect indentation level 12, expected level should be 6. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:8:13: warning: 'if' has incorrect indentation level 12, expected level should be 6. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
return new int[]{map.get(complement), i};

Check warning on line 9 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'if' child has incorrect indentation level 16, expected level should be 8. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:9:17: warning: 'if' child has incorrect indentation level 16, expected level should be 8. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
}

Check warning on line 10 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'if rcurly' has incorrect indentation level 12, expected level should be 6. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:10:13: warning: 'if rcurly' has incorrect indentation level 12, expected level should be 6. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
map.put(nums[i], i);

Check warning on line 11 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'for' child has incorrect indentation level 12, expected level should be 6. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:11:13: warning: 'for' child has incorrect indentation level 12, expected level should be 6. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
}

Check warning on line 12 in Solved-Problems/Two_Sum/Solution.java

View workflow job for this annotation

GitHub Actions / java-linter / java-linter

[reviewdog] reported by reviewdog 🐶 'for rcurly' has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./Solved-Problems/Two_Sum/Solution.java:12:9: warning: 'for rcurly' has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
return new int[]{};
}
}
Comment on lines +3 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format your code to pass the linting checks.

Suggested change
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[]{map.get(complement), i};
}
map.put(nums[i], i);
}
return new int[]{};
}
}
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[] {map.get(complement), i};
}
map.put(nums[i], i);
}
return new int[] {};
}
}

1 change: 1 addition & 0 deletions index.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the changes for this file. These changes will be updated automatically by the automation scripts when your PR is successfully merged.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Welcome to **Data Structures and Algorithms**, your friendly initiation into the
- [Backspace_String_Compare](Solved-Problems/Backspace_String_Compare "goto Backspace_String_Compare")
- [Longest_Substring_Without_Repeating_Characters](Solved-Problems/Longest_Substring_Without_Repeating_Characters "goto Longest_Substring_Without_Repeating_Characters")
- [Valid_Anagram](Solved-Problems/Valid_Anagram "goto Valid_Anagram")
- [Two Sum](./Two_Sum/Solution.java "goto Two_Sum problem and finding target in an array LeetCode - 1")
<!-- TABLE OF CONTENT ENDS -->

# Table of Contribution
Expand Down
Loading