Skip to content
Merged
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
21 changes: 21 additions & 0 deletions src/ReverseInteger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class ReverseInteger {
public int reverse(int x) {
long r = 0;
while (x != 0) {
int carry = x % 10;
x = x / 10;
r = r * 10 + carry;
if (r > Integer.MAX_VALUE || r < Integer.MIN_VALUE) {
return 0;
}
}
return (int)r;
}

public static void main(String[] args) {
int input = 120;
ReverseInteger solution = new ReverseInteger();
int output = solution.reverse(input);
System.out.println(output);
}
}
9 changes: 4 additions & 5 deletions src/TwoSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
import java.util.Hashtable;

public class TwoSum {
public int[] twoSum(int[] listIn, int target) {

public int[] twoSum(int[] nums, int target) {
Hashtable<Integer, Integer> h = new Hashtable<>();
for (int i = 0; i < listIn.length; i++) {
int tmp = target - listIn[i];
for (int i = 0; i < nums.length; i++) {
int tmp = target - nums[i];
if (h.containsKey(tmp)) {
return new int[]{h.get(tmp), i};
}
h.put(listIn[i], i);
h.put(nums[i], i);
}
return new int[]{};
}
Expand Down