Not a member of GistPad yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- // Time Complexity = O(N)
- StringBuilder sb = new StringBuilder();
- char ch = '.'; // after each string from the list append a dot to segeregate
- {
- sb.append(s).append(ch);
- }
- return sb.toString();
- }
- // Time Complexity = O(N)
- List<String> list = new ArrayList<>();
- StringBuilder sb = new StringBuilder();
- for(char ch : str.toCharArray())
- {
- if(ch != '.')
- sb.append(ch);
- else
- {
- // when dot is encountered, then add the current string to list
- list.add(sb.toString());
- // empty the current string
- sb = new StringBuilder();
- }
- }
- return list;
- }
- }
RAW Paste Data
Copied
