Skip to content

Commit 37ef1ea

Browse files
authored
Added task 3374
1 parent d21e0ea commit 37ef1ea

File tree

16 files changed

+99
-19
lines changed
  • src/main/java
    • g0001_0100
    • g0201_0300/s0282_expression_add_operators
    • g0401_0500
    • g0501_0600/s0520_detect_capital
    • g0601_0700/s0664_strange_printer
    • g0701_0800/s0761_special_binary_string
    • g1001_1100/s1002_find_common_characters
    • g1101_1200/s1138_alphabet_board_path
    • g1701_1800/s1704_determine_if_string_halves_are_alike
    • g1801_1900/s1898_maximum_number_of_removable_characters
    • g1901_2000/s1948_delete_duplicate_folders_in_system
    • g3301_3400/s3374_first_letter_capitalization_ii

16 files changed

+99
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,7 @@
18161816

18171817
| # | Title | Difficulty | Tag | Time, ms | Time, %
18181818
|------|----------------|-------------|-------------|----------|--------
1819+
| 3374 |[First Letter Capitalization II](src/main/java/g3301_3400/s3374_first_letter_capitalization_ii)| Hard | Database | 261 | 84.21
18191820
| 3373 |[Maximize the Number of Target Nodes After Connecting Trees II](src/main/java/g3301_3400/s3373_maximize_the_number_of_target_nodes_after_connecting_trees_ii)| Hard | Depth_First_Search, Breadth_First_Search, Tree | 26 | 98.75
18201821
| 3372 |[Maximize the Number of Target Nodes After Connecting Trees I](src/main/java/g3301_3400/s3372_maximize_the_number_of_target_nodes_after_connecting_trees_i)| Medium | Depth_First_Search, Breadth_First_Search, Tree | 50 | 99.49
18211822
| 3371 |[Identify the Largest Outlier in an Array](src/main/java/g3301_3400/s3371_identify_the_largest_outlier_in_an_array)| Medium | Array, Hash_Table, Counting, Enumeration | 5 | 100.00

src/main/java/g0001_0100/s0014_longest_common_prefix/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Solution {
4343
String temp = strs[0];
4444
int i = 1;
4545
String cur;
46-
while (temp.length() > 0 && i < strs.length) {
46+
while (!temp.isEmpty() && i < strs.length) {
4747
if (temp.length() > strs[i].length()) {
4848
temp = temp.substring(0, strs[i].length());
4949
}

src/main/java/g0001_0100/s0065_valid_number/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Given a string `s`, return `true` _if_ `s` _is a **valid number**_.
6161
```java
6262
public class Solution {
6363
public boolean isNumber(String s) {
64-
if (s == null || s.length() == 0) {
64+
if (s == null || s.isEmpty()) {
6565
return false;
6666
}
6767
boolean eSeen = false;

src/main/java/g0201_0300/s0282_expression_add_operators/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import java.util.List;
7171
public class Solution {
7272
public List<String> addOperators(String num, int target) {
7373
List<String> res = new ArrayList<>();
74-
if (num.length() == 0 || Long.parseLong(num) > Integer.MAX_VALUE) {
74+
if (num.isEmpty() || Long.parseLong(num) > Integer.MAX_VALUE) {
7575
return res;
7676
}
7777
char[] list = num.toCharArray();

src/main/java/g0401_0500/s0434_number_of_segments_in_a_string/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ A **segment** is defined to be a contiguous sequence of **non-space characters**
3535
public class Solution {
3636
public int countSegments(String s) {
3737
s = s.trim();
38-
if (s.length() == 0) {
38+
if (s.isEmpty()) {
3939
return 0;
4040
}
4141
String[] splitted = s.split(" ");
4242
int result = 0;
4343
for (String value : splitted) {
44-
if (value.length() > 0) {
44+
if (!value.isEmpty()) {
4545
result++;
4646
}
4747
}

src/main/java/g0401_0500/s0468_validate_ip_address/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class Solution {
5252
private static final String NEITHER = "Neither";
5353

5454
public String validIPAddress(String ip) {
55-
if (ip.length() == 0) {
55+
if (ip.isEmpty()) {
5656
return NEITHER;
5757
}
5858
String[] arr = ip.split("\\.", -1);
@@ -70,7 +70,7 @@ public class Solution {
7070
return "IPv4";
7171
} else if (arr1.length == 8) {
7272
for (String num : arr1) {
73-
if (num.length() < 1 || num.length() > 4) {
73+
if (num.isEmpty() || num.length() > 4) {
7474
return NEITHER;
7575
}
7676
for (int j = 0; j < num.length(); j++) {

src/main/java/g0401_0500/s0488_zuma_game/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public class Solution {
8484
}
8585

8686
private int findMinStepDp(String board, String hand, Map<String, Map<String, Integer>> dp) {
87-
if (board.length() == 0) {
87+
if (board.isEmpty()) {
8888
return 0;
8989
}
90-
if (hand.length() == 0) {
90+
if (hand.isEmpty()) {
9191
return -1;
9292
}
9393
if (dp.get(board) != null && dp.get(board).get(hand) != null) {

src/main/java/g0501_0600/s0520_detect_capital/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Given a string `word`, return `true` if the usage of capitals in it is right.
3535
```java
3636
public class Solution {
3737
public boolean detectCapitalUse(String word) {
38-
if (word == null || word.length() == 0) {
38+
if (word == null || word.isEmpty()) {
3939
return false;
4040
}
4141
int upper = 0;

src/main/java/g0601_0700/s0664_strange_printer/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Given a string `s`, return _the minimum number of turns the printer needed to pr
3838
```java
3939
public class Solution {
4040
public int strangePrinter(String s) {
41-
if (s.length() == 0) {
41+
if (s.isEmpty()) {
4242
return 0;
4343
}
4444
int[][] dp = new int[s.length()][s.length()];

src/main/java/g0701_0800/s0761_special_binary_string/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import java.util.PriorityQueue;
4646

4747
public class Solution {
4848
public String makeLargestSpecial(String s) {
49-
if (s == null || s.length() == 0 || s.length() == 2) {
49+
if (s == null || s.isEmpty() || s.length() == 2) {
5050
return s;
5151
}
5252
PriorityQueue<String> pq = new PriorityQueue<>((a, b) -> b.compareTo(a));
@@ -72,7 +72,7 @@ public class Solution {
7272
while (!pq.isEmpty()) {
7373
ans.append(pq.poll());
7474
}
75-
if (ans.length() == 0) {
75+
if (ans.isEmpty()) {
7676
ans.append('1');
7777
ans.append(makeLargestSpecial(s.substring(1, s.length() - 1)));
7878
ans.append('0');

src/main/java/g1001_1100/s1002_find_common_characters/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class Solution {
5252
}
5353

5454
private String getCommon(String s1, String s2) {
55-
if (s1.length() == 0 || s2.length() == 0) {
55+
if (s1.isEmpty() || s2.isEmpty()) {
5656
return "";
5757
}
5858
int[] c1c = countChars(s1);

src/main/java/g1101_1200/s1138_alphabet_board_path/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Return a sequence of moves that makes our answer equal to `target` in the minimu
4545
```java
4646
public class Solution {
4747
public String alphabetBoardPath(String target) {
48-
if (target.length() == 0) {
48+
if (target.isEmpty()) {
4949
return "";
5050
}
5151
int sourceRow = 0;

src/main/java/g1701_1800/s1704_determine_if_string_halves_are_alike/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Return `true` _if_ `a` _and_ `b` _are **alike**_. Otherwise, return `false`.
3838
```java
3939
public class Solution {
4040
public boolean halvesAreAlike(String s) {
41-
if (s.length() < 1) {
41+
if (s.isEmpty()) {
4242
return false;
4343
}
4444
return countVowel(0, s.length() / 2, s) == countVowel(s.length() / 2, s.length(), s);

src/main/java/g1801_1900/s1898_maximum_number_of_removable_characters/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Hence, the maximum k is 2.
5959
```java
6060
public class Solution {
6161
public int maximumRemovals(String s, String p, int[] removable) {
62-
if (s == null || s.length() == 0) {
62+
if (s == null || s.isEmpty()) {
6363
return 0;
6464
}
6565
// binary search for the k which need to be removed

src/main/java/g1901_2000/s1948_delete_duplicate_folders_in_system/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ public class Solution {
132132
folder.calculateHash();
133133
builder.append('#');
134134
builder.append(foldername);
135-
if (folder.folderHash.length() > 0) {
135+
if (!folder.folderHash.isEmpty()) {
136136
builder.append('(');
137137
builder.append(folder.folderHash);
138138
builder.append(')');
139139
}
140140
}
141141
folderHash = builder.toString();
142-
if (folderHash.length() > 0) {
142+
if (!folderHash.isEmpty()) {
143143
ArrayList<Folder> duplicateFolders =
144144
duplicates.computeIfAbsent(folderHash, k -> new ArrayList<>());
145145
duplicateFolders.add(this);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Java?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Java)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Java?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Java/fork)
3+
4+
## 3374\. First Letter Capitalization II
5+
6+
Hard
7+
8+
SQL Schema
9+
10+
Table: `user_content`
11+
12+
+-------------+---------+
13+
| Column Name | Type |
14+
+-------------+---------+
15+
| content_id | int |
16+
| content_text| varchar |
17+
+-------------+---------+
18+
content_id is the unique key for this table. Each row contains a unique ID and the corresponding text content.
19+
20+
Write a solution to transform the text in the `content_text` column by applying the following rules:
21+
22+
* Convert the **first letter** of each word to **uppercase** and the **remaining** letters to **lowercase**
23+
* Special handling for words containing special characters:
24+
* For words connected with a hyphen `-`, **both parts** should be **capitalized** (**e.g.**, top-rated → Top-Rated)
25+
* All other **formatting** and **spacing** should remain **unchanged**
26+
27+
Return _the result table that includes both the original `content_text` and the modified text following the above rules_.
28+
29+
The result format is in the following example.
30+
31+
**Example:**
32+
33+
**Input:**
34+
35+
user\_content table:
36+
37+
+------------+---------------------------------+
38+
| content_id | content_text |
39+
+------------+---------------------------------+
40+
| 1 | hello world of SQL |
41+
| 2 | the QUICK-brown fox |
42+
| 3 | modern-day DATA science |
43+
| 4 | web-based FRONT-end development |
44+
+------------+---------------------------------+
45+
46+
**Output:**
47+
48+
+------------+---------------------------------+---------------------------------+
49+
| content_id | original_text | converted_text |
50+
+------------+---------------------------------+---------------------------------+
51+
| 1 | hello world of SQL | Hello World Of Sql |
52+
| 2 | the QUICK-brown fox | The Quick-Brown Fox |
53+
| 3 | modern-day DATA science | Modern-Day Data Science |
54+
| 4 | web-based FRONT-end development | Web-Based Front-End Development |
55+
+------------+---------------------------------+---------------------------------+
56+
57+
**Explanation:**
58+
59+
* For content\_id = 1:
60+
* Each word's first letter is capitalized: "Hello World Of Sql"
61+
* For content\_id = 2:
62+
* Contains the hyphenated word "QUICK-brown" which becomes "Quick-Brown"
63+
* Other words follow normal capitalization rules
64+
* For content\_id = 3:
65+
* Hyphenated word "modern-day" becomes "Modern-Day"
66+
* "DATA" is converted to "Data"
67+
* For content\_id = 4:
68+
* Contains two hyphenated words: "web-based" → "Web-Based"
69+
* And "FRONT-end" → "Front-End"
70+
71+
## Solution
72+
73+
```python
74+
import pandas as pd
75+
76+
def capitalize_content(user_content):
77+
user_content['converted_text'] = (user_content.content_text.apply(lambda x: x.title()))
78+
return user_content.rename(columns={'content_text': 'original_text'})
79+
```

0 commit comments

Comments
 (0)