Skip to content

Commit 528d448

Browse files
solves di string match
1 parent 5ffa62f commit 528d448

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LeetCode Algorithms
22

3-
![problems-solved](https://img.shields.io/badge/Problems%20Solved-215/2081-1f425f.svg)
4-
![problems-solved-java](https://img.shields.io/badge/Java-215/2081-1abc9c.svg)
3+
![problems-solved](https://img.shields.io/badge/Problems%20Solved-220/2081-1f425f.svg)
4+
![problems-solved-java](https://img.shields.io/badge/Java-220/2081-1abc9c.svg)
55
![problems-solved-python](https://img.shields.io/badge/Python-186/2081-1abc9c.svg)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
77
[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming)
@@ -255,7 +255,7 @@
255255
| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | [![Java](assets/java.png)](src/ReorderDataInLogFiles.java) |
256256
| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [![Java](assets/java.png)](src/RangeSumOfBST.java) |
257257
| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | |
258-
| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | |
258+
| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | [![Java](assets/java.png)](src/DIStringMatch.java) |
259259
| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | |
260260
| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | |
261261
| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | |

src/DIStringMatch.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class DIStringMatch {
2+
public int[] diStringMatch(String s) {
3+
int[] result = new int[s.length() + 1];
4+
int current = 0;
5+
for (int i = 0 ; i < s.length() ; i++) {
6+
if (s.charAt(i) == 'I') result[i] = current++;
7+
}
8+
result[result.length - 1] = current++;
9+
for (int i = s.length() - 1 ; i >= 0 ; i--) {
10+
if (s.charAt(i) == 'D') result[i] = current++;
11+
}
12+
return result;
13+
}
14+
}

0 commit comments

Comments
 (0)