课程: Java Algorithms
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Apply custom parsing to search algorithms
- [Instructor] Sometimes you'll need to parse the string yourself in order to retrieve the data you're looking for. Let's say we wanted to find out if a certain character exists at an even index or an even location within the string. In this case, we'll need to access the location of the character as well as the character in the string itself. This means we'll use a for loop. Now, instead of incrementing, I by one, we could actually increment I by two. We only need to check the even indices of the string, since we're checking whether the item is at an even index, we can skip over the odd indices, cutting our time complexity in half. With this new incrementation, we'll need to change our conditions so we don't get a null pointer exception in the body of the for loop. We don't want to try to access a character at an invalid location. Since we're skipping every other indices in the string, we can change our condition to s.length divided by two plus one. Now let's add some code to the for…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
Validate Strings in Java: All-or-nothing properties4 分钟 17 秒
-
(已锁定)
Validate strings in Java: Specific properties2 分钟 58 秒
-
(已锁定)
Normalize strings in Java4 分钟 38 秒
-
(已锁定)
Basic parsing and searching strings in Java3 分钟 39 秒
-
(已锁定)
Apply custom parsing to search algorithms3 分钟 24 秒
-
(已锁定)
Create algorithm-driven strings in Java3 分钟 46 秒
-
(已锁定)
Leverage built-in tools to generate custom data2 分钟 30 秒
-
(已锁定)
Solution: Reverse each word3 分钟 32 秒
-
-
-
-
-
-
-