Skip to content

Commit

Permalink
update 833 java, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 17, 2024
1 parent 40e8785 commit 83fed7d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@
824| [Goat Latin](https://leetcode.com/problems/goat-latin/) | [Python](./leetcode_python/String/goat-latin.py) | _O(n + w^2)_ | _O(l)_ | Easy| `string basic`, `fb`| OK
828| [Count Unique Characters of All Substrings of a Given String](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/) | [Python](./leetcode_python/String/count-unique-characters-of-all-substrings-of-a-given-string.py) | _O(n + w^2)_ | _O(l)_ | Hard| LC 1248, dp, `string`, `amazon`| AGAIN*** (2)
831| [Masking Personal Information](https://leetcode.com/problems/masking-personal-information/) | [Python](./leetcode_python/String/masking-personal-information.py) | _O(1)_ | _O(1)_ | Medium |`regular expression`| OK*
833| [Find And Replace in String](https://leetcode.com/problems/find-and-replace-in-string/) | [Python](./leetcode_python/String/find-and-replace-in-string.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/String/FindAndReplaceInString.java) | _O(n + m)_ | _O(n)_ | Medium | hashmap, string, google| AGAIN (2) (not start)
833| [Find And Replace in String](https://leetcode.com/problems/find-and-replace-in-string/) | [Python](./leetcode_python/String/find-and-replace-in-string.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/String/FindAndReplaceInString.java) | _O(n + m)_ | _O(n)_ | Medium | good basic, string op, hashmap, google| AGAIN****** (3)
848 | [Shifting Letters](https://leetcode.com/problems/shifting-letters/) | [Python](./leetcode_python/String/shifting-letters.py) | _O(n)_ | _O(1)_ | Medium |`remainder`, `basic`| AGAIN**
859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Python](./leetcode_python/String/buddy-strings.py) | _O(n)_ | _O(1)_ | Easy || AGAIN*
880 | [Decoded String at Index](https://leetcode.com/problems/decoded-string-at-index/) | [Python](./leetcode_python/String/decoded-string-at-index.py) | _O(n)_ | _O(1)_ | Medium |`trick`| AGAIN (not start**)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@
* s consists of only lowercase English letters.
* sources[i] and targets[i] consist of only lowercase English letters.
*/
/**
* NOTE !!!
*
* -> The testcases will be generated such that the replacements will not overlap.
* (All replacement operations must occur simultaneously,
* meaning the replacement operations should not affect the
* indexing of each other. The testcases will be generated
* such that the replacements will not overlap.)
*
* -> e.g. case like below will NOT happen:
*
* s = "abc", indices = [0, 1], and sources = ["ab","bc"]
*
* -> so, it's NO NEEDED that our code to handle scenario as above
*
*/
public class FindAndReplaceInString {

// V0
Expand Down
34 changes: 30 additions & 4 deletions leetcode_java/src/main/java/dev/workspace5.java
Original file line number Diff line number Diff line change
Expand Up @@ -3194,13 +3194,39 @@ public int maxSubArray(int[] nums) {

// LC 833
// https://leetcode.com/problems/find-and-replace-in-string/
// 4.23 pm - 4.40 pm
// 6.50 - 7.10 pm
public String findReplaceString(String s, int[] indices, String[] sources, String[] targets) {

// if (sources.length == 1 && targets.length == 1){
// }
if (indices.length == 0){
return s;
}

return null;
// re-order indices
Arrays.sort(indices);

// check if overlap
//boolean isOverlap = false;
if (isOverlap(s, indices)){
return s;
}

Map<Integer, String> map = new HashMap<>();
for (int i = 0; i < indices.length; i++){
map.put(i, targets[i]);
}

String res = "";
String[] sArray = s.split("");
for (int j = indices.length; j > 0; j++){
sArray[j] = map.get(j);
}

// array -> string
return sArray.toString(); // ?
}

private boolean isOverlap(String s, int[] indices){
return false;
}

// LC 950
Expand Down

0 comments on commit 83fed7d

Please sign in to comment.