Skip to content

Commit 284b1fa

Browse files
committed
Added 3 solutions
1 parent 0350d42 commit 284b1fa

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

Easy/1-bit and 2-bit Characters.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public boolean isOneBitCharacter(int[] bits) {
3+
int l = bits.length;
4+
int i = 0;
5+
6+
while(i<l-1) {
7+
if(bits[i] == 0) {
8+
i++;
9+
}
10+
else {
11+
i += 2;
12+
}
13+
}
14+
return i == l-1;
15+
}
16+
}

Easy/FizzBuzz.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ else if (i%5==0) {
1717
}
1818
return myList;
1919
}
20-
}
20+
}

Easy/add_digit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ public int addDigits(int num) {
1818
return 0;
1919
}
2020
}
21-
}
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int numSubarrayProductLessThanK(int[] nums, int k) {
3+
if (k<2) return 0;
4+
int result = 0;
5+
int product = 1;
6+
for (int i = 0, right = 0; right < nums.length; right++) {
7+
product *= nums[right];
8+
while (i < nums.length && product >= k) {
9+
product /= nums[i++];
10+
}
11+
result += right - i + 1;
12+
}
13+
return result;
14+
}
15+
}

Medium/Teemo Attacking.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int findPoisonedDuration(int[] timeSeries, int duration) {
3+
4+
if (timeSeries.length == 0 || duration == 0) return 0;
5+
6+
int begin = timeSeries[0], total = 0;
7+
for (int t : timeSeries) {
8+
total = total + (t < begin + duration ? t - begin : duration);
9+
begin = t;
10+
}
11+
12+
return total + duration;
13+
}
14+
}

0 commit comments

Comments
 (0)