Skip to content

Commit 64324e3

Browse files
committed
formatted code: remove extra spaces/newlines
1 parent 6a642a0 commit 64324e3

33 files changed

+89
-92
lines changed

0001-two-sum.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
1616
return [i, d[want]]
1717
else:
1818
d[nums[i]] = i
19-

0009-palindrome-number.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Solution {
1313
if (x < 0) return false;
1414
// Reverse digits
1515
long y = 0;
16-
int x2 = x;
16+
int x2 = x;
1717
while (x2 != 0) {
1818
y *= 10;
1919
y += x2 % 10;

0014-longest-common-prefix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ char* longestCommonPrefix(char** strs, int strsSize) {
2121
char* prefix = calloc(len_shortest + 1, sizeof(char));
2222
for (unsigned char i = 0; i < len_shortest; i++) {
2323
for (char** p = strs; p != strsEnd; ++p ) {
24-
char* str = *p;
24+
char* str = *p;
2525
// this means that the prefix ends here
2626
if (str[i] != strs[0][i]) return prefix;
2727
}

0020-valid-parentheses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Solution {
1515
for (const char& c : s) {
1616
if (c == '(' || c == '[' || c == '{') { // opening parentheses
1717
stack.push_back(c);
18-
} else if (stack.empty() ||
18+
} else if (stack.empty() ||
1919
stack.back() != (c == ')' ? '(' : // matching closing
2020
c == ']' ? '[' : // parentheses with
2121
c == '}' ? '{' : // open parentheses

0035-search-insert-position.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def bs(a, h, l, x): # begin binary search function
2121
else:
2222
return -1
2323
# end binary search function
24-
if target in nums:
24+
if target in nums:
2525
r = bs(nums, len(nums), 0, target)
2626
if r >= 0:
2727
return r
@@ -39,4 +39,4 @@ def bs(a, h, l, x): # begin binary search function
3939
for i in range(len(nums)):
4040
if nums[i] > target:
4141
return i
42-
return -1 # not found
42+
return -1 # not found

0141-linked-list-cycle.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
Last submitted: September 30, 2024
66
Submitted: September 26, 2024
77
8-
Runtime: 40 ms (beats 83.76%)
8+
Runtime: 40 ms (beats 83.76%)
99
Memory: 19.15 MB (beats 33.41%)
1010
"""
1111

12-
1312
# Definition for singly-linked list.
1413
# class ListNode:
1514
# def __init__(self, x):
@@ -25,4 +24,4 @@ def hasCycle(self, head: Optional[ListNode]) -> bool:
2524
fast = fast.next.next
2625
if slow is fast:
2726
return True
28-
return False
27+
return False

0146-lru-cache.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class LinkedList {
2121
private:
2222
Node* const head = new Node(-1, -1);
2323
Node* const tail = new Node(-2, -2);
24-
size_type currentSize = 0;
24+
size_type currentSize = 0;
2525

2626
inline void validateNode(Node* node) const {
2727
if (node == nullptr) throw invalid_argument("Node cannot be null");
@@ -93,15 +93,15 @@ class LRUCache {
9393
LinkedList list;
9494
public:
9595
LRUCache(int capacity) : capacity((LinkedList::size_type) capacity) {}
96-
96+
9797
int get(int key) {
9898
if (map.count(key)) {
9999
list.moveToHead(map[key]);
100100
return map[key]->val;
101101
}
102102
return -1;
103103
}
104-
104+
105105
void put(int key, int value) {
106106
if (map.count(key)) {
107107
list.moveToHead(map[key]);

0150-evaluate-reverse-polish-notation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Submitted: November 16, 2024
55
6-
Runtime: 0 ms (beats 100.00%)
6+
Runtime: 0 ms (beats 100.00%)
77
Memory: 15.74 MB (beats 61.18%)
88
*/
99

@@ -42,4 +42,4 @@ class Solution {
4242
}
4343
return stack.top();
4444
}
45-
};
45+
};

0150-evaluate-reverse-polish-notation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ def evalRPN(self, tokens: List[str]) -> int:
1515
x = stack.pop()
1616
y = stack.pop()
1717
stack.append(x + y)
18-
elif token == "-":
18+
elif token == "-":
1919
y = stack.pop()
2020
x = stack.pop()
2121
stack.append(x - y)
22-
elif token == "*":
22+
elif token == "*":
2323
x = stack.pop()
2424
y = stack.pop()
2525
stack.append(x * y)
26-
elif token == "/":
26+
elif token == "/":
2727
y = stack.pop()
2828
x = stack.pop()
2929
stack.append(int(x / y))
3030
else:
3131
stack.append(int(token))
32-
return stack[-1]
32+
return stack[-1]

0175-combine-two-tables.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Runtime: 399 ms (beats 83.54%)
77
*/
88

99
# Write your MySQL query statement below
10-
SELECT firstName, lastName, city, state
11-
FROM Person
10+
SELECT firstName, lastName, city, state
11+
FROM Person
1212
LEFT JOIN Address -- we need to use LEFT JOIN so that `null` is produced if the
13-
USING (personId); -- address of a Person is not found in Address
13+
USING (personId); -- address of a Person is not found in Address

0193-valid-phone-numbers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
while read REPLY; do # read line into $REPLY until EOF
1010
[[ $REPLY =~ ^[0-9]{3}-[0-9]{3}-[0-9]{4}$ ]] || # if $REPLY matches regex for nnn-nnn-nnnn
1111
[[ $REPLY =~ ^\([0-9]{3}\)\ [0-9]{3}\-[0-9]{4}$ ]] && # if $REPLY matches regex for (nnn) nnn-nnnn
12-
echo $REPLY
12+
echo $REPLY
1313
done < file.txt # redirect stdin to read from file.txt
1414
# all in one line:
1515
# while read REPLY; do [[ $REPLY =~ ^[0-9]{3}-[0-9]{3}-[0-9]{4}$ ]] || [[ $REPLY =~ ^\([0-9]{3}\)\ [0-9]{3}\-[0-9]{4}$ ]] && echo $REPLY; done < file.txt

0202-happy-number.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Solution {
1616
fast = sumDigits(sumDigits(fast));
1717
slow = sumDigits(slow);
1818
}
19-
if (fast == 1) return true;
19+
if (fast == 1) return true;
2020
return false;
2121
}
2222
int sumDigits(int n) { // sum squares of digits
@@ -28,4 +28,4 @@ class Solution {
2828
}
2929
return res;
3030
}
31-
};
31+
};

0203-remove-linked-list-elements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNod
2020
while p:
2121
while p.next and p.next.val == val:
2222
p.next = p.next.next
23-
p = p.next
23+
p = p.next
2424
return dummy.next

0217-contains-duplicate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Submitted: October 4, 2024
55
Runtime: 414 ms (beats 5.53%)
6-
Memory: 35.63 MB (beats 8.45)
6+
Memory: 35.63 MB (beats 8.45)
77
"""
88

99
class Solution:
@@ -13,4 +13,4 @@ def containsDuplicate(self, nums: List[int]) -> bool:
1313
if nums[i] in map:
1414
return True
1515
map[nums[i]] = i
16-
return False
16+
return False

0242-valid-anagram.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Memory: 10.10 MB (beats 17.76%)
99
*/
1010

1111
/*
12-
Approach:
13-
We count the number of times each character appears in the two strings. If they
12+
Approach:
13+
We count the number of times each character appears in the two strings. If they
1414
are equal, they must be anagrams.
1515
*/
1616

@@ -27,4 +27,4 @@ class Solution {
2727
}
2828
return s_count == t_count;
2929
}
30-
};
30+
};

0387-first-unique-character-in-a-string.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Memory: 12.95 MB (beats 94.71%)
1010
class Solution {
1111
public:
1212
int firstUniqChar(string s) {
13-
int occurrences[26] = { 0 }; // using an array as a map w/ fixed values
13+
int occurrences[26] = { 0 }; // using an array as a map w/ fixed values
1414
for (const char& c : s) {
1515
occurrences[c - 'a']++;
1616
}
@@ -19,4 +19,4 @@ class Solution {
1919
}
2020
return -1;
2121
}
22-
};
22+
};

0476-number-compliment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Solution {
1818
n >>= 1; // digits has the same number of `1` bits as
1919
digits <<= 1; // the number of digits total in `n` when you
2020
digits++; // remove leading zeroes
21-
}
21+
}
2222
return d ^ digits; // 1 ^ 1 = 0, 0 ^ 1 = 1
2323
}
24-
};
24+
};

0482-license-key-formatting.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ class Solution {
1212
string licenseKeyFormatting(string s, int k) {
1313
unsigned short i = 0;
1414
string result;
15-
// we go through the string backwards so that the first group can
15+
// we go through the string backwards so that the first group can
1616
// contain less than `k` digits. it's easier to make the last group
1717
// different than the first group different.
18-
for (auto it = s.crbegin(); it != s.crend(); ++it) {
18+
for (auto it = s.crbegin(); it != s.crend(); ++it) {
1919
const char& c = *it;
2020
if (c == '-') { // ignore hyphens
2121
continue;
2222
} else if (i == k) { // after k non-hyphen characters, append a hyphen
2323
result.push_back('-');
2424
i = 0;
25-
}
25+
}
2626
result.push_back(c >= 'a' ? c - 32 : c); // convert to uppercase
2727
++i;
2828
}
2929
reverse(result.begin(), result.end());
3030
return result;
3131
}
32-
};
32+
};

0504-base-7.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Solution {
1313
if (num == 0) return "0";
1414
string res = "";
1515
bool negative = false;
16-
if (num < 0) {
16+
if (num < 0) {
1717
negative = true;
1818
num = -num;
1919
}
@@ -24,4 +24,4 @@ class Solution {
2424
if (negative) res.insert(0, 1, '-');
2525
return res;
2626
}
27-
};
27+
};

0804-unique-morse-code-words.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@ class Solution {
1616
for (const char& c : word) {
1717
s.append(c == 'a' ? ".-" : // nested ternary operators
1818
c == 'b' ? "-..." : // in place of map
19-
c == 'c' ? "-.-." :
20-
c == 'd' ? "-.." :
21-
c == 'e' ? "." :
22-
c == 'f' ? "..-." :
23-
c == 'g' ? "--." :
24-
c == 'h' ? "...." :
25-
c == 'i' ? ".." :
26-
c == 'j' ? ".---" :
27-
c == 'k' ? "-.-" :
28-
c == 'l' ? ".-.." :
29-
c == 'm' ? "--" :
30-
c == 'n' ? "-." :
31-
c == 'o' ? "---" :
32-
c == 'p' ? ".--." :
33-
c == 'q' ? "--.-" :
34-
c == 'r' ? ".-." :
35-
c == 's' ? "..." :
36-
c == 't' ? "-" :
37-
c == 'u' ? "..-" :
38-
c == 'v' ? "...-" :
39-
c == 'w' ? ".--" :
40-
c == 'x' ? "-..-" :
41-
c == 'y' ? "-.--" :
42-
c == 'z' ? "--.." :
19+
c == 'c' ? "-.-." :
20+
c == 'd' ? "-.." :
21+
c == 'e' ? "." :
22+
c == 'f' ? "..-." :
23+
c == 'g' ? "--." :
24+
c == 'h' ? "...." :
25+
c == 'i' ? ".." :
26+
c == 'j' ? ".---" :
27+
c == 'k' ? "-.-" :
28+
c == 'l' ? ".-.." :
29+
c == 'm' ? "--" :
30+
c == 'n' ? "-." :
31+
c == 'o' ? "---" :
32+
c == 'p' ? ".--." :
33+
c == 'q' ? "--.-" :
34+
c == 'r' ? ".-." :
35+
c == 's' ? "..." :
36+
c == 't' ? "-" :
37+
c == 'u' ? "..-" :
38+
c == 'v' ? "...-" :
39+
c == 'w' ? ".--" :
40+
c == 'x' ? "-..-" :
41+
c == 'y' ? "-.--" :
42+
c == 'z' ? "--.." :
4343
""); // fail condition
4444
}
4545
set.emplace(s);
4646
}
4747
return set.size();
4848
}
49-
};
49+
};

1281-subtract-the-product-and-sum-of-digits-of-an-integer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Memory: 7.55 MB (beats 13.43%)
1010
class Solution {
1111
public:
1212
int subtractProductAndSum(int n) {
13-
int digitProduct = 1;
13+
int digitProduct = 1;
1414
int p = n;
1515
while (p != 0) {
1616
digitProduct *= p % 10;
@@ -25,4 +25,4 @@ class Solution {
2525
cout << digitProduct << " " << digitSum;
2626
return digitProduct - digitSum;
2727
}
28-
};
28+
};

1313-decompress-run-length-encoded-list.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ int* decompressRLElist(int* nums, int numsSize, int* returnSize) {
2525
int freq = *p;
2626
int val = *(++p);
2727
for (unsigned char i = 0; i < freq; ++i) {
28-
*r = val;
28+
*r = val;
2929
++r;
3030
}
3131
p++;
3232
}
3333
return returnArray;
34-
}
34+
}

1455-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Solution {
1717
words.push_back(sentence.substr(0, sentence.find(' '))); // first split
1818
while ((pos = sentence.find(' ', pos)) != string::npos) { // other splits
1919
// pos + 1 since sentence[pos] == ' '
20-
words.push_back(sentence.substr(pos + 1, pos + sws + 1));
20+
words.push_back(sentence.substr(pos + 1, pos + sws + 1));
2121
pos++;
2222
}
2323
for (unsigned char i = 0, n = words.size(); i < n; ++i) {

1486-xor-operation-in-an-array.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Submitted: October 28, 2024
55
66
Runtime: 0 ms (beats 100.00%)
7-
Memory: 7.31 MB (beats 84.96%)
7+
Memory: 7.31 MB (beats 84.96%)
88
*/
99

1010
class Solution {
@@ -16,4 +16,4 @@ class Solution {
1616
}
1717
return res;
1818
}
19-
};
19+
};

0 commit comments

Comments
 (0)