Skip to content

Commit

Permalink
Solution for bwc-89
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariel Rivero LLerena authored and Dariel Rivero LLerena committed Oct 16, 2022
1 parent 17f6cff commit 0882cc7
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ from [Hacker Rank](https://www.hackerrank.com/dashboard),
| Online Judge Problems | Easy | Medium | Hard | Advanced | Total |
|:-----------------------------------------------------------------------:|:----:|:------:|:----:|:--------:|:-----:|
| [HackerRank](/src/main/java/drll/problems/hackerRank/SolvedProblems.md) | 9 | 14 | 3 | 1 | 27 |
| [LeetCode](/src/main/java/drll/problems/leetcode/SolvedProblems.md) | 43 | 55 | 1 | | 99 |
| | | | | | 126 |
| [LeetCode](/src/main/java/drll/problems/leetcode/SolvedProblems.md) | 44 | 55 | 1 | | 100 |
| | | | | | 127 |

##### My current classification in the online judges

| Online Judge | Rank | Points | Update Day | Trend* ▲▼ ◄► |
|:------------:|:------:|:-------:|:----------:|:-------------:|
| HackerRank | 132835 | 1040.63 | 09/04/22 ||
| LeetCode | 529848 | 1263 | 10/10/22 | 2|
| LeetCode | 529423 | 1272 | 15/10/22 | |
*: Trend of the observed ranking

#### CLI
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Link to the problem

- https://leetcode.com/problems/number-of-valid-clock-times/

##### Difficulty Level (according to Leetcode)

> Easy ( String )

##### Resume of the problem:


##### Notes

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package drll.problems.leetcode.NumberOfValidClockTimes;

public class Solution {
public int countTime(String time) {
String[] splitTime = time.split(":");
String hours = splitTime[0];
String minutes = splitTime[1];

int validHoursTimes = 1;
int validMinutesTimes = 1;

if(hours.charAt(0) == '?'){
if(hours.charAt(1) == '?'){
validHoursTimes = 3;
}
else{
int hour = Integer.parseInt(String.valueOf(hours.charAt(1)));
validHoursTimes = hour < 4 ? 3 : 2;
}
}
if(hours.charAt(1) == '?'){
if(hours.charAt(0) == '?'){
validHoursTimes = 24;
}
else{
validHoursTimes = hours.charAt(0) == '0' || hours.charAt(0) == '1' ? 10 : 4;
}
}


if(minutes.charAt(0) == '?'){
validMinutesTimes = 6;
}
if(minutes.charAt(1) == '?'){
validMinutesTimes = minutes.charAt(0) == '?' ? 60 : 10;
}

return validHoursTimes * validMinutesTimes;
}
}
5 changes: 3 additions & 2 deletions src/main/java/drll/problems/leetcode/SolvedProblems.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

## Resume for 99 Leetcode solved problems
## Resume for 100 Leetcode solved problems

### According to leetcode classification*1

Expand All @@ -14,7 +14,7 @@
| Recursion(1) | | |
| Implementation(1) | | |
| Search | | |
| String(22) | | |
| String(23) | | |
| Binary Search(1) | | |


Expand Down Expand Up @@ -121,6 +121,7 @@
| 97 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element/) | Array | Easy | SOLVED |
| 98 | [Optimal Partition of String](https://leetcode.com/problems/optimal-partition-of-string/) | String | Medium | SOLVED |
| 99 | [Divide Intervals Into Minimum Number of Groups](https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/) | Array | Medium | SOLVED |
|100 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times/) | String | Easy | SOLVED |

---
###### 1-2: Taking in account only the first related topic for the problem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package drll.problems.leetcode.NumberOfValidClockTimes;

import drll.problems.leetcode.NumberOfValidClockTimes.Solution;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class SolutionTest {
private Solution solution;

@BeforeEach
void init(){
solution = new Solution();
}

@Test
void should_return_correctly_for_test_case1() {
assertThat(solution.countTime("?5:00")).isEqualTo(2);
}

@Test
void should_return_correctly_for_test_case2() {
assertThat(solution.countTime("0?:0?")).isEqualTo(100);
}

@Test
void should_return_correctly_for_test_case3() {
assertThat(solution.countTime("??:??")).isEqualTo(1440);
}

@Test
void should_return_correctly_for_test_case4() {
assertThat(solution.countTime("07:?3")).isEqualTo(6);
}
}

0 comments on commit 0882cc7

Please sign in to comment.