Loading...
Loading...
Comprehensive code reviewer for Java and Python implementations focusing on correctness, efficiency, code quality, and algorithmic optimization. Reviews LeetCode solutions, data structures, and algorithm implementations. Use when reviewing code, checking solutions, or providing feedback on implementations.
npx skill4agent add yennanliu/cs_basics java-python-code-reviewer[]""nullNone[1]"a"[1,1,1][-1, -5]Current: O(n²) time, O(1) space
Optimal: O(n) time, O(n) space using HashMap
Trade-off: Use extra space for better time complexityArrayListHashMapHashSetList<Integer>List<>ArrayList<>// Bad: Raw types
ArrayList list = new ArrayList();
// Good: Generics
List<Integer> list = new ArrayList<>();
// Bad: Manual array copying
for (int i = 0; i < arr.length; i++) { ... }
// Good: Built-in methods
Arrays.copyOf(arr, arr.length);
// Bad: String concatenation in loop
String s = "";
for (String str : list) { s += str; }
// Good: StringBuilder
StringBuilder sb = new StringBuilder();
for (String str : list) { sb.append(str); }longsetdictdeque# Bad: Manual index tracking
for i in range(len(arr)):
print(i, arr[i])
# Good: enumerate
for i, val in enumerate(arr):
print(i, val)
# Bad: Building list with append in loop
result = []
for x in arr:
result.append(x * 2)
# Good: List comprehension
result = [x * 2 for x in arr]
# Bad: Multiple membership checks
if x == 'a' or x == 'b' or x == 'c':
# Good: Use set or tuple
if x in {'a', 'b', 'c'}:collections.defaultdictCounterNone## Correctness: ✓ Pass / ⚠ Issues Found
[List any correctness issues]
## Complexity Analysis
- Time: O(?) - [Explain]
- Space: O(?) - [Explain]
- Optimal: [If current solution is not optimal]
## Code Quality
**Strengths:**
- [List positive aspects]
**Issues:**
- [Issue 1] at line X: [Explanation]
- [Issue 2] at line Y: [Explanation]
**Suggestions:**
- [Suggestion 1]: [Why it's better]
- [Suggestion 2]: [Why it's better]
## Overall Assessment
[Summary and recommendation]// Code under review
public int[] twoSum(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return new int[]{};
}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[]{};
}leetcode_java/leetcode_python/algorithm/data_structure/doc/