Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
yaozc
ProjectLeet
Commits
47030270
Commit
47030270
authored
Aug 05, 2019
by
zhayao
Browse files
keep going
parent
beb751fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
amazon.cpp
View file @
47030270
...
...
@@ -1670,17 +1670,35 @@ Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-
Word
Break
class
Solution
{
public:
bool
wordBreak
(
string
s
,
vector
<
string
>&
wordDict
)
{
unordered_set
<
string
>
dict
;
for
(
auto
&
key
:
wordDict
){
dict
.
insert
(
key
);
}
vector
<
bool
>
matched
(
s
.
size
(),
false
);
int
last_match_pos
=
0
;
for
(
int
i
=
0
;
i
<
s
.
size
();
i
++
){
string
sub
=
s
.
substr
(
last_match_pos
,
i
-
last_match_pos
);
cout
<<
sub
<<
endl
;
auto
it
=
dict
.
find
(
sub
);
if
(
it
!=
dict
.
end
()){
dict
.
for
(
int
inner
=
0
;
inner
<
sub
.
size
();
inner
++
){
matched
[
inner
+
last_match_pos
]
=
true
;
}
last_match_pos
=
i
+
1
;
}
}
for
(
int
i
=
0
;
i
<
matched
.
size
();
i
++
){
if
(
!
matched
[
i
])
return
false
;
}
return
true
;
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment