Skip to content

Commit a6ee4a7

Browse files
committed
Additional work
1 parent 9ad2de7 commit a6ee4a7

13 files changed

+210
-6
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Large diffs are not rendered by default.

my-submissions/m1561.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def maxCoins(self, piles: List[int]) -> int:
3+
piles = deque(sorted(piles))
4+
5+
output: int = 0
6+
while piles :
7+
piles.pop()
8+
output += piles.pop()
9+
piles.popleft()
10+
11+
return output

my-submissions/m1833.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
int comp(const void* a, const void* b) {
2+
return *((int*) a) - *((int*) b);
3+
}
4+
5+
int maxIceCream(int* costs, int costsSize, int coins) {
6+
qsort(costs, costsSize, sizeof(int), comp);
7+
8+
for (int i = 0; i < costsSize; i++) {
9+
if (coins < costs[i])
10+
return i;
11+
coins -= costs[i];
12+
}
13+
14+
return costsSize;
15+
}

my-submissions/m1833.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int maxIceCream(int[] costs, int coins) {
3+
Arrays.sort(costs);
4+
5+
for (int i = 0; i < costs.length; i++) {
6+
if (coins < costs[i])
7+
return i;
8+
coins -= costs[i];
9+
}
10+
11+
return costs.length;
12+
}
13+
}

my-submissions/m1833.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def maxIceCream(self, costs: List[int], coins: int) -> int:
3+
bars = 0
4+
costs.sort(reverse=True)
5+
6+
while costs :
7+
if coins < costs[-1] :
8+
return bars
9+
bars += 1
10+
coins -= costs.pop()
11+
12+
return bars

my-submissions/m1877 nlogn.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def minPairSum(self, nums: List[int]) -> int:
3+
nums.sort()
4+
maxx = 0
5+
6+
for i in range(len(nums) // 2) :
7+
maxx = max(maxx, nums[i] + nums[len(nums) - i - 1])
8+
9+
return maxx

my-submissions/m2405 v1 26-List.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Wanted to see if a 26-long list being reset each time would be faster
2+
# than a hashmap
3+
4+
class Solution:
5+
def partitionString(self, s: str) -> int:
6+
current: List[bool] = [False] * 26
7+
8+
counter = 1
9+
for c in s :
10+
if current[ord(c) - ord('a')] :
11+
counter += 1
12+
current = [False] * 26
13+
current[ord(c) - ord('a')] = True
14+
15+
else :
16+
current[ord(c) - ord('a')] = True
17+
18+
return counter
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def partitionString(self, s: str) -> int:
3+
lastCase: List[int] = [-1] * 26
4+
5+
counter = 1
6+
leftPointer = 0
7+
for i, c in enumerate(s) :
8+
if lastCase[ord(c) - ord('a')] >= leftPointer :
9+
leftPointer = i
10+
counter += 1
11+
lastCase[ord(c) - ord('a')] = i
12+
13+
return counter

my-submissions/m2405 v2 Set.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def partitionString(self, s: str) -> int:
3+
current = set()
4+
5+
counter = 1
6+
for c in s :
7+
if c in current :
8+
counter += 1
9+
current = set()
10+
current.add(c)
11+
12+
return counter

my-submissions/m50.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
double myPowLong(double x, long n) {
2+
if (n == 0)
3+
return 1.;
4+
5+
if (n < 0)
6+
return 1 / myPowLong(x, n * -1);
7+
8+
if (n == 1)
9+
return x;
10+
11+
double half = myPowLong(x, n / 2);
12+
long remainder = n % 2;
13+
14+
if (remainder == 1)
15+
return half * half * x;
16+
return half * half;
17+
}
18+
19+
double myPow(double x, int n) {
20+
return myPowLong(x, (long) n);
21+
}

my-submissions/m50.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public double myPow(double x, int n) {
3+
return myPow(x, (long) n);
4+
5+
}
6+
private double myPow(double x, long n) {
7+
if (n == 0)
8+
return 1.;
9+
10+
if (n < 0)
11+
return 1 / myPow(x, n * -1);
12+
13+
if (n == 1)
14+
return x;
15+
16+
double half = myPow(x, n / 2);
17+
long remainder = n % 2;
18+
19+
if (remainder == 1)
20+
return half * half * x;
21+
return half * half;
22+
}
23+
}

my-submissions/m50.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def myPow(self, x: float, n: int) -> float:
3+
if not n :
4+
return 1
5+
6+
if n == 1 :
7+
return x
8+
9+
if n < 0 :
10+
return 1 / self.myPow(x, -n)
11+
12+
half = n // 2
13+
remainder = n - half * 2
14+
half = self.myPow(x, half)
15+
16+
if remainder :
17+
return x * half * half
18+
19+
return half * half

my-submissions/m98.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* struct TreeNode *left;
6+
* struct TreeNode *right;
7+
* };
8+
*/
9+
10+
bool isValidBSTHelper(struct TreeNode* root, long min, long max) {
11+
if (!root)
12+
return true;
13+
14+
if ((long) root->val <= min || (long) root->val >= max)
15+
return false;
16+
17+
bool output = true;
18+
19+
if (root->right)
20+
output &= root->val < root->right->val
21+
&& isValidBSTHelper(root->right, (long) root->val, max);
22+
23+
if (root->left)
24+
output &= root->left->val < root->val
25+
&& isValidBSTHelper(root->left, min, (long) root->val);
26+
27+
return output;
28+
}
29+
30+
bool isValidBST(struct TreeNode* root) {
31+
return isValidBSTHelper(root, LONG_MIN, LONG_MAX);
32+
}

0 commit comments

Comments
 (0)