Skip to content

Commit e9a0525

Browse files
Kevin Naughton JrKevin Naughton Jr
authored andcommitted
fix formatting
1 parent 614c349 commit e9a0525

File tree

310 files changed

+2055
-4707
lines changed

Some content is hidden

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

310 files changed

+2055
-4707
lines changed

.DS_Store

8 KB
Binary file not shown.

Company/.DS_Store

18 KB
Binary file not shown.

Company/Airbnb/addTwoNumbers.java renamed to Company/Airbnb/AddTwoNumbers.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
* ListNode(int x) { val = x; }
1414
* }
1515
*/
16-
public class Solution {
17-
16+
public class AddTwoNumbers {
1817
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
19-
2018
ListNode current1 = l1;
2119
ListNode current2 = l2;
2220

Company/Airbnb/convertSortedArrayToBinarySearchTree.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@
1010
* }
1111
*/
1212
public class Solution {
13-
1413
public TreeNode sortedArrayToBST(int[] nums) {
15-
16-
if(nums.length == 0) return null;
14+
if(nums.length == 0) {
15+
return null;
16+
}
1717

1818
TreeNode root = helper(nums, 0, nums.length - 1);
1919

2020
return root;
21-
2221
}
2322

2423
private TreeNode helper(int[] nums, int start, int end) {
25-
2624
if(start <= end) {
27-
2825
int mid = (start + end) / 2;
2926

3027
TreeNode current = new TreeNode(nums[mid]);
@@ -33,11 +30,8 @@ private TreeNode helper(int[] nums, int start, int end) {
3330
current.right = helper(nums, mid + 1, end);
3431

3532
return current;
36-
3733
}
3834

3935
return null;
40-
4136
}
42-
43-
}
37+
}

Company/Airbnb/houseRobber.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,29 @@
22

33
// Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
44

5-
public class Solution {
6-
5+
public class HouseRobber {
76
public int rob(int[] nums) {
8-
9-
if(nums.length == 0) return 0;
10-
if(nums.length == 1) return nums[0];
7+
if(nums.length == 0) {
8+
return 0;
9+
}
10+
11+
if(nums.length == 1) {
12+
return nums[0];
13+
}
1114

1215
int[] dp = new int[nums.length];
1316

1417
dp[0] = nums[0];
1518
dp[1] = nums[0] > nums[1] ? nums[0] : nums[1];
1619

1720
for(int i = 2; i < nums.length; i++) {
18-
1921
dp[i] = Math.max(dp[i - 2] + nums[i], dp[i - 1]);
20-
2122
}
22-
23+
2324
for(int i = 0; i < dp.length; i++) {
24-
2525
System.out.print(dp[i] + " ");
26-
2726
}
2827

2928
return dp[dp.length - 1];
30-
3129
}
32-
33-
}
30+
}

Company/Airbnb/mergeKSortedLists.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,44 @@
88
* ListNode(int x) { val = x; }
99
* }
1010
*/
11-
public class Solution {
12-
11+
public class MergeKSortedLists {
1312
public ListNode mergeKLists(ListNode[] lists) {
14-
15-
if (lists==null||lists.length==0) return null;
13+
if (lists==null||lists.length==0) {
14+
return null;
15+
}
1616

1717
PriorityQueue<ListNode> queue= new PriorityQueue<ListNode>(lists.length,new Comparator<ListNode>(){
1818
@Override
1919
public int compare(ListNode o1,ListNode o2){
20-
if (o1.val<o2.val)
20+
if (o1.val<o2.val) {
2121
return -1;
22-
else if (o1.val==o2.val)
22+
} else if (o1.val==o2.val) {
2323
return 0;
24-
else
24+
} else {
2525
return 1;
26+
}
2627
}
2728
});
2829

2930
ListNode dummy = new ListNode(0);
3031
ListNode tail=dummy;
3132

32-
for (ListNode node:lists)
33-
if (node!=null)
33+
for (ListNode node:lists) {
34+
if (node!=null) {
3435
queue.add(node);
35-
36-
while (!queue.isEmpty()){
36+
}
37+
}
38+
39+
while (!queue.isEmpty()) {
3740
tail.next=queue.poll();
3841
tail=tail.next;
39-
40-
if (tail.next!=null)
42+
43+
if (tail.next!=null) {
4144
queue.add(tail.next);
45+
}
46+
4247
}
4348
return dummy.next;
44-
}
4549

46-
}
50+
}
51+
}

Company/Airbnb/regularExpressionMatching.java

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,41 @@
1717
// isMatch("ab", ".*") → true
1818
// isMatch("aab", "c*a*b") → true
1919

20-
public class Solution {
21-
20+
public class RegularExpressionMatching {
2221
public boolean isMatch(String s, String p) {
23-
24-
if(s == null || p == null) return false;
22+
if(s == null || p == null) {
23+
return false;
24+
}
2525

2626
boolean[][] dp = new boolean[s.length() + 1][p.length() + 1];
2727
dp[0][0] = true;
2828

2929
for(int i = 0; i < p.length(); i++) {
30-
3130
if(p.charAt(i) == '*' && dp[0][i - 1]) {
32-
3331
dp[0][i + 1] = true;
34-
3532
}
36-
3733
}
3834

3935
for(int i = 0; i < s.length(); i++) {
40-
4136
for(int j = 0; j < p.length(); j++) {
42-
4337
if(p.charAt(j) == '.') {
44-
4538
dp[i + 1][j + 1] = dp[i][j];
46-
4739
}
4840

4941
if(p.charAt(j) == s.charAt(i)) {
50-
5142
dp[i + 1][j + 1] = dp[i][j];
52-
5343
}
5444

5545
if(p.charAt(j) == '*') {
56-
5746
if(p.charAt(j - 1) != s.charAt(i) && p.charAt(j - 1) != '.') {
58-
5947
dp[i + 1][j + 1] = dp[i + 1][j - 1];
60-
61-
}
62-
63-
else {
64-
48+
} else {
6549
dp[i + 1][j + 1] = (dp[i + 1][j] || dp[i][j + 1] || dp[i + 1][j - 1]);
66-
6750
}
68-
6951
}
70-
7152
}
72-
7353
}
7454

7555
return dp[s.length()][p.length()];
76-
7756
}
78-
79-
}
57+
}

Company/Airbnb/twoSum.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,23 @@
88
// Because nums[0] + nums[1] = 2 + 7 = 9,
99
// return [0, 1].
1010

11-
public class Solution {
12-
11+
public class TwoSum {
1312
public int[] twoSum(int[] nums, int target) {
14-
1513
int[] result = new int[2];
1614

1715
HashMap<Integer, Integer> map = new HashMap<>();
1816

1917
for(int i = 0; i < nums.length; i++) {
20-
2118
if(map.containsKey(target - nums[i])) {
22-
2319
result[1] = i;
2420
result[0] = map.get(target - nums[i]);
21+
2522
return result;
26-
2723
}
2824

2925
map.put(nums[i], i);
30-
3126
}
3227

3328
return result;
34-
3529
}
36-
37-
}
30+
}

Company/Airbnb/validParentheses.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,28 @@
22

33
// The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.
44

5-
public class Solution {
6-
5+
public class ValidParentheses {
76
public boolean isValid(String s) {
8-
97
if(s.length() % 2 == 1) {
10-
118
return false;
12-
139
}
1410

1511
Stack<Character> stack = new Stack<Character>();
1612

1713
for(int i = 0; i < s.length(); i++) {
18-
1914
if(s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{') {
20-
2115
stack.push(s.charAt(i));
22-
23-
}
24-
25-
else if(s.charAt(i) == ')' && !stack.isEmpty() && stack.peek() == '(') {
26-
16+
} else if(s.charAt(i) == ')' && !stack.isEmpty() && stack.peek() == '(') {
2717
stack.pop();
28-
29-
}
30-
31-
else if(s.charAt(i) == ']' && !stack.isEmpty() && stack.peek() == '[') {
32-
18+
} else if(s.charAt(i) == ']' && !stack.isEmpty() && stack.peek() == '[') {
3319
stack.pop();
34-
35-
}
36-
37-
else if(s.charAt(i) == '}' && !stack.isEmpty() && stack.peek() == '{') {
38-
20+
} else if(s.charAt(i) == '}' && !stack.isEmpty() && stack.peek() == '{') {
3921
stack.pop();
40-
41-
}
42-
43-
else {
44-
22+
} else {
4523
return false;
46-
4724
}
48-
4925
}
5026

5127
return stack.isEmpty();
52-
5328
}
54-
5529
}

Company/Amazon/3Sum.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,23 @@
1010
// [-1, -1, 2]
1111
// ]
1212

13-
public class Solution {
14-
13+
public class 3Sum {
1514
public List<List<Integer>> threeSum(int[] nums) {
16-
1715
List<List<Integer>> result = new ArrayList<>();
1816

1917
Arrays.sort(nums);
2018

2119
for(int i = 0; i < nums.length - 2; i++) {
22-
2320
if(i > 0 && nums[i] == nums[i - 1]) {
24-
2521
continue;
26-
2722
}
2823

2924
int j = i + 1;
3025
int k = nums.length - 1;
3126
int target = -nums[i];
3227

3328
while(j < k) {
34-
3529
if(nums[j] + nums[k] == target) {
36-
3730
ArrayList<Integer> temp = new ArrayList<Integer>();
3831

3932
temp.add(nums[i]);
@@ -45,29 +38,21 @@ public List<List<Integer>> threeSum(int[] nums) {
4538
j++;
4639
k--;
4740

48-
while(j < k && nums[j] == nums[j - 1]) j++;
49-
while(j < k && nums[k] == nums[k + 1]) k--;
50-
51-
}
52-
53-
else if(nums[j] + nums[k] > target) {
41+
while(j < k && nums[j] == nums[j - 1]) {
42+
j++;
43+
}
5444

45+
while(j < k && nums[k] == nums[k + 1]) {
46+
k--;
47+
}
48+
} else if(nums[j] + nums[k] > target) {
5549
k--;
56-
57-
}
58-
59-
else {
60-
50+
} else {
6151
j++;
62-
6352
}
64-
6553
}
66-
6754
}
6855

6956
return result;
70-
7157
}
72-
73-
}
58+
}

0 commit comments

Comments
 (0)