Skip to content

Commit 83fed7d

Browse files
committed
update 833 java, readme
1 parent 40e8785 commit 83fed7d

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@
635635
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
636636
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)
637637
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*
638-
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)
638+
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)
639639
848 | [Shifting Letters](https://leetcode.com/problems/shifting-letters/) | [Python](./leetcode_python/String/shifting-letters.py) | _O(n)_ | _O(1)_ | Medium |`remainder`, `basic`| AGAIN**
640640
859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Python](./leetcode_python/String/buddy-strings.py) | _O(n)_ | _O(1)_ | Easy || AGAIN*
641641
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**)

leetcode_java/src/main/java/LeetCodeJava/String/FindAndReplaceInString.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@
5757
* s consists of only lowercase English letters.
5858
* sources[i] and targets[i] consist of only lowercase English letters.
5959
*/
60+
/**
61+
* NOTE !!!
62+
*
63+
* -> The testcases will be generated such that the replacements will not overlap.
64+
* (All replacement operations must occur simultaneously,
65+
* meaning the replacement operations should not affect the
66+
* indexing of each other. The testcases will be generated
67+
* such that the replacements will not overlap.)
68+
*
69+
* -> e.g. case like below will NOT happen:
70+
*
71+
* s = "abc", indices = [0, 1], and sources = ["ab","bc"]
72+
*
73+
* -> so, it's NO NEEDED that our code to handle scenario as above
74+
*
75+
*/
6076
public class FindAndReplaceInString {
6177

6278
// V0

leetcode_java/src/main/java/dev/workspace5.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,13 +3194,39 @@ public int maxSubArray(int[] nums) {
31943194

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

3200-
// if (sources.length == 1 && targets.length == 1){
3201-
// }
3200+
if (indices.length == 0){
3201+
return s;
3202+
}
32023203

3203-
return null;
3204+
// re-order indices
3205+
Arrays.sort(indices);
3206+
3207+
// check if overlap
3208+
//boolean isOverlap = false;
3209+
if (isOverlap(s, indices)){
3210+
return s;
3211+
}
3212+
3213+
Map<Integer, String> map = new HashMap<>();
3214+
for (int i = 0; i < indices.length; i++){
3215+
map.put(i, targets[i]);
3216+
}
3217+
3218+
String res = "";
3219+
String[] sArray = s.split("");
3220+
for (int j = indices.length; j > 0; j++){
3221+
sArray[j] = map.get(j);
3222+
}
3223+
3224+
// array -> string
3225+
return sArray.toString(); // ?
3226+
}
3227+
3228+
private boolean isOverlap(String s, int[] indices){
3229+
return false;
32043230
}
32053231

32063232
// LC 950

0 commit comments

Comments
 (0)