Skip to content

Commit d7150f6

Browse files
committed
style: format code
1 parent 7808672 commit d7150f6

File tree

476 files changed

+880
-809
lines changed

Some content is hidden

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

476 files changed

+880
-809
lines changed

lcci/01.02.Check Permutation/Solution.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ class Solution {
33
bool CheckPermutation(string s1, string s2) {
44
if (s1.size() != s2.size()) return false;
55
int cnt[26] = {0};
6-
for (char & c : s1) ++cnt[c - 'a'];
7-
for (char & c : s2) if (--cnt[c - 'a'] < 0) return false;
6+
for (char& c : s1) ++cnt[c - 'a'];
7+
for (char& c : s2)
8+
if (--cnt[c - 'a'] < 0) return false;
89
return true;
910
}
1011
};

lcci/01.04.Palindrome Permutation/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Solution {
22
public boolean canPermutePalindrome(String s) {
3-
Map<Character, Integer> cnt = new HashMap<>();
3+
Map<Character, Integer> cnt = new HashMap<>();
44
for (int i = 0; i < s.length(); ++i) {
55
cnt.merge(s.charAt(i), 1, Integer::sum);
66
}

lcci/01.08.Zero Matrix/Solution.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void setZeroes(int **matrix, int matrixSize, int *matrixColSize) {
1+
void setZeroes(int** matrix, int matrixSize, int* matrixColSize) {
22
int m = matrixSize;
33
int n = matrixColSize[0];
44
int l0 = 0;

lcci/03.02.Min Stack/Solution.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ class MinStack {
66
public MinStack() {
77
stk2.push(Integer.MAX_VALUE);
88
}
9-
9+
1010
public void push(int x) {
1111
stk1.push(x);
1212
stk2.push(Math.min(x, stk2.peek()));
1313
}
14-
14+
1515
public void pop() {
1616
stk1.pop();
1717
stk2.pop();
1818
}
19-
19+
2020
public int top() {
2121
return stk1.peek();
2222
}
23-
23+
2424
public int getMin() {
2525
return stk2.peek();
2626
}

lcci/03.03.Stack of Plates/Solution.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class StackOfPlates {
55
public StackOfPlates(int cap) {
66
this.cap = cap;
77
}
8-
8+
99
public void push(int val) {
1010
if (cap == 0) {
1111
return;
@@ -15,11 +15,11 @@ public void push(int val) {
1515
}
1616
stk.get(stk.size() - 1).push(val);
1717
}
18-
18+
1919
public int pop() {
2020
return popAt(stk.size() - 1);
2121
}
22-
22+
2323
public int popAt(int index) {
2424
int ans = -1;
2525
if (index >= 0 && index < stk.size()) {

lcci/08.10.Color Fill/Solution.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
1313
}
1414

1515
private void dfs(int i, int j) {
16-
if (i < 0 || i >= image.length || j < 0 || j >= image[0].length || image[i][j] != oc || image[i][j] == nc) {
16+
if (i < 0 || i >= image.length || j < 0 || j >= image[0].length || image[i][j] != oc
17+
|| image[i][j] == nc) {
1718
return;
1819
}
1920
image[i][j] = nc;

lcci/16.02.Words Frequency/Solution.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class WordsFrequency {
55
++cnt[x];
66
}
77
}
8-
8+
99
int get(string word) {
1010
return cnt[word];
1111
}

lcci/16.02.Words Frequency/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public WordsFrequency(String[] book) {
66
cnt.merge(x, 1, Integer::sum);
77
}
88
}
9-
9+
1010
public int get(String word) {
1111
return cnt.getOrDefault(word, 0);
1212
}

lcci/16.14.Best Line/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ class Solution {
138138
int g = gcd(dx, dy);
139139
String key = (dx / g) + "." + (dy / g);
140140
cnt.computeIfAbsent(key, k -> new ArrayList<>()).add(new int[] {i, j});
141-
if (mx < cnt.get(key).size() || (mx == cnt.get(key).size() && (ans[0] > cnt.get(key).get(0)[0] || (ans[0] == cnt.get(key).get(0)[0] && ans[1] > cnt.get(key).get(0)[1])))) {
141+
if (mx < cnt.get(key).size()
142+
|| (mx == cnt.get(key).size()
143+
&& (ans[0] > cnt.get(key).get(0)[0]
144+
|| (ans[0] == cnt.get(key).get(0)[0]
145+
&& ans[1] > cnt.get(key).get(0)[1])))) {
142146
mx = cnt.get(key).size();
143147
ans = cnt.get(key).get(0);
144148
}

lcci/16.14.Best Line/README_EN.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ class Solution {
120120
int g = gcd(dx, dy);
121121
String key = (dx / g) + "." + (dy / g);
122122
cnt.computeIfAbsent(key, k -> new ArrayList<>()).add(new int[] {i, j});
123-
if (mx < cnt.get(key).size() || (mx == cnt.get(key).size() && (ans[0] > cnt.get(key).get(0)[0] || (ans[0] == cnt.get(key).get(0)[0] && ans[1] > cnt.get(key).get(0)[1])))) {
123+
if (mx < cnt.get(key).size()
124+
|| (mx == cnt.get(key).size()
125+
&& (ans[0] > cnt.get(key).get(0)[0]
126+
|| (ans[0] == cnt.get(key).get(0)[0]
127+
&& ans[1] > cnt.get(key).get(0)[1])))) {
124128
mx = cnt.get(key).size();
125129
ans = cnt.get(key).get(0);
126130
}

lcci/17.09.Get Kth Magic Number/Solution.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#define min(a,b) (((a) < (b)) ? (a) : (b))
1+
#define min(a, b) (((a) < (b)) ? (a) : (b))
22

33
int getKthMagicNumber(int k) {
4-
int *dp = (int *) malloc(sizeof(int) * k);
4+
int* dp = (int*) malloc(sizeof(int) * k);
55
dp[0] = 1;
66
int index[3] = {0, 0, 0};
77
for (int i = 1; i < k; i++) {

lcci/17.19.Missing Two/Solution.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ class Solution {
88

99
int diff = eor & -eor;
1010
int a = 0;
11-
for (int v : nums) if (v & diff) a ^= v;
12-
for (int i = 1; i <= n; ++i) if (i & diff) a ^= i;
11+
for (int v : nums)
12+
if (v & diff) a ^= v;
13+
for (int i = 1; i <= n; ++i)
14+
if (i & diff) a ^= i;
1315
int b = eor ^ a;
1416
return {a, b};
1517
}

lcci/17.20.Continuous Median/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class MedianFinder {
9292

9393
/** initialize your data structure here. */
9494
public MedianFinder() {
95-
9695
}
9796

9897
public void addNum(int num) {

lcci/17.20.Continuous Median/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class MedianFinder {
8080

8181
/** initialize your data structure here. */
8282
public MedianFinder() {
83-
8483
}
8584

8685
public void addNum(int num) {

lcci/17.20.Continuous Median/Solution.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ class MedianFinder {
22
public:
33
/** initialize your data structure here. */
44
MedianFinder() {
5-
65
}
7-
6+
87
void addNum(int num) {
98
q1.push(num);
109
q2.push(q1.top());
@@ -14,7 +13,7 @@ class MedianFinder {
1413
q2.pop();
1514
}
1615
}
17-
16+
1817
double findMedian() {
1918
if (q2.size() > q1.size()) {
2019
return q2.top();

lcci/17.20.Continuous Median/Solution.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ class MedianFinder {
44

55
/** initialize your data structure here. */
66
public MedianFinder() {
7-
87
}
9-
8+
109
public void addNum(int num) {
1110
q1.offer(num);
1211
q2.offer(q1.poll());
1312
if (q2.size() - q1.size() > 1) {
1413
q1.offer(q2.poll());
1514
}
1615
}
17-
16+
1817
public double findMedian() {
1918
if (q2.size() > q1.size()) {
2019
return q2.peek();

lcof/面试题03. 数组中重复的数字/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Solution {
104104
```java
105105
class Solution {
106106
public int findRepeatNumber(int[] nums) {
107-
for (int i = 0; ; ++i) {
107+
for (int i = 0;; ++i) {
108108
while (nums[i] != i) {
109109
int j = nums[i];
110110
if (nums[j] == j) {

lcof/面试题03. 数组中重复的数字/Solution.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Solution {
22
public:
33
int findRepeatNumber(vector<int>& nums) {
4-
for (int i = 0; ; ++i) {
4+
for (int i = 0;; ++i) {
55
while (nums[i] != i) {
66
int j = nums[i];
77
if (nums[j] == j) {

lcof/面试题03. 数组中重复的数字/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Solution {
22
public int findRepeatNumber(int[] nums) {
3-
for (int i = 0; ; ++i) {
3+
for (int i = 0;; ++i) {
44
while (nums[i] != i) {
55
int j = nums[i];
66
if (nums[j] == j) {

lcof/面试题09. 用两个栈实现队列/Solution.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
class CQueue {
22
public:
33
CQueue() {
4-
54
}
6-
5+
76
void appendTail(int value) {
87
stk1.push(value);
98
}
10-
9+
1110
int deleteHead() {
1211
if (stk2.empty()) {
1312
while (!stk1.empty()) {

lcof/面试题19. 正则表达式匹配/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ class Solution {
169169
if (i > 0 && (p.charAt(j - 2) == '.' || p.charAt(j - 2) == s.charAt(i - 1))) {
170170
f[i][j] |= f[i - 1][j];
171171
}
172-
} else if (i > 0 && (p.charAt(j - 1) == '.' || p.charAt(j - 1) == s.charAt(i - 1))) {
172+
} else if (i > 0
173+
&& (p.charAt(j - 1) == '.' || p.charAt(j - 1) == s.charAt(i - 1))) {
173174
f[i][j] = f[i - 1][j - 1];
174175
}
175176
}

lcof/面试题19. 正则表达式匹配/Solution.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public boolean isMatch(String s, String p) {
1010
if (i > 0 && (p.charAt(j - 2) == '.' || p.charAt(j - 2) == s.charAt(i - 1))) {
1111
f[i][j] |= f[i - 1][j];
1212
}
13-
} else if (i > 0 && (p.charAt(j - 1) == '.' || p.charAt(j - 1) == s.charAt(i - 1))) {
13+
} else if (i > 0
14+
&& (p.charAt(j - 1) == '.' || p.charAt(j - 1) == s.charAt(i - 1))) {
1415
f[i][j] = f[i - 1][j - 1];
1516
}
1617
}

lcof/面试题20. 表示数值的字符串/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class Solution {
170170
boolean e = false;
171171
for (; i <= j; ++i) {
172172
if (s.charAt(i) == '+' || s.charAt(i) == '-') {
173-
if (i > 0 && s.charAt(i - 1) != ' ' && s.charAt(i - 1) != 'e' && s.charAt(i - 1) != 'E') {
173+
if (i > 0 && s.charAt(i - 1) != ' ' && s.charAt(i - 1) != 'e'
174+
&& s.charAt(i - 1) != 'E') {
174175
return false;
175176
}
176177
} else if (Character.isDigit(s.charAt(i))) {

lcof/面试题20. 表示数值的字符串/Solution.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public boolean isNumber(String s) {
1515
boolean e = false;
1616
for (; i <= j; ++i) {
1717
if (s.charAt(i) == '+' || s.charAt(i) == '-') {
18-
if (i > 0 && s.charAt(i - 1) != ' ' && s.charAt(i - 1) != 'e' && s.charAt(i - 1) != 'E') {
18+
if (i > 0 && s.charAt(i - 1) != ' ' && s.charAt(i - 1) != 'e'
19+
&& s.charAt(i - 1) != 'E') {
1920
return false;
2021
}
2122
} else if (Character.isDigit(s.charAt(i))) {

lcof/面试题30. 包含min函数的栈/Solution.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ class MinStack {
66
public MinStack() {
77
stk2.push(Integer.MAX_VALUE);
88
}
9-
9+
1010
public void push(int x) {
1111
stk1.push(x);
1212
stk2.push(Math.min(x, stk2.peek()));
1313
}
14-
14+
1515
public void pop() {
1616
stk1.pop();
1717
stk2.pop();
1818
}
19-
19+
2020
public int top() {
2121
return stk1.peek();
2222
}
23-
23+
2424
public int getMin() {
2525
return stk2.peek();
2626
}

lcof/面试题32 - I. 从上到下打印二叉树/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Solution {
8686
}
8787
Deque<TreeNode> q = new ArrayDeque<>();
8888
q.offer(root);
89-
List<Integer> res = new ArrayList<>();
89+
List<Integer> res = new ArrayList<>();
9090
while (!q.isEmpty()) {
9191
for (int n = q.size(); n > 0; --n) {
9292
TreeNode node = q.poll();

lcof/面试题32 - I. 从上到下打印二叉树/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public int[] levelOrder(TreeNode root) {
1414
}
1515
Deque<TreeNode> q = new ArrayDeque<>();
1616
q.offer(root);
17-
List<Integer> res = new ArrayList<>();
17+
List<Integer> res = new ArrayList<>();
1818
while (!q.isEmpty()) {
1919
for (int n = q.size(); n > 0; --n) {
2020
TreeNode node = q.poll();

lcof/面试题32 - II. 从上到下打印二叉树 II/Solution.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Solution {
1212
vector<vector<int>> levelOrder(TreeNode* root) {
1313
vector<vector<int>> ans;
1414
if (!root) return ans;
15-
queue<TreeNode*> q {{root}};
15+
queue<TreeNode*> q{{root}};
1616
while (!q.empty()) {
1717
vector<int> t;
1818
for (int n = q.size(); n; --n) {

lcof/面试题34. 二叉树中和为某一值的路径/Solution.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Solution {
1414
vector<vector<int>> pathSum(TreeNode* root, int target) {
1515
vector<vector<int>> ans;
1616
vector<int> t;
17-
function<void(TreeNode* root, int s)> dfs = [&](TreeNode* root, int s) {
17+
function<void(TreeNode * root, int s)> dfs = [&](TreeNode* root, int s) {
1818
if (!root) {
1919
return;
2020
}

lcof/面试题35. 复杂链表的复制/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Solution {
209209
if (head == null) {
210210
return null;
211211
}
212-
for (Node cur = head; cur != null; ) {
212+
for (Node cur = head; cur != null;) {
213213
Node node = new Node(cur.val, cur.next);
214214
cur.next = node;
215215
cur = node.next;
@@ -220,7 +220,7 @@ class Solution {
220220
}
221221
}
222222
Node ans = head.next;
223-
for (Node cur = head; cur != null; ) {
223+
for (Node cur = head; cur != null;) {
224224
Node nxt = cur.next;
225225
if (nxt != null) {
226226
cur.next = nxt.next;

lcof/面试题35. 复杂链表的复制/Solution.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Solution {
1919
if (!head) {
2020
return nullptr;
2121
}
22-
for (Node* cur = head; cur; ) {
22+
for (Node* cur = head; cur;) {
2323
Node* node = new Node(cur->val);
2424
node->next = cur->next;
2525
cur->next = node;
@@ -31,7 +31,7 @@ class Solution {
3131
}
3232
}
3333
Node* ans = head->next;
34-
for (Node* cur = head; cur; ) {
34+
for (Node* cur = head; cur;) {
3535
Node* nxt = cur->next;
3636
if (nxt) {
3737
cur->next = nxt->next;

0 commit comments

Comments
 (0)