[ 
https://issues.apache.org/jira/browse/GROOVY-11655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17950243#comment-17950243
 ] 

ASF GitHub Bot commented on GROOVY-11655:
-----------------------------------------

dongwq commented on PR #2215:
URL: https://github.com/apache/groovy/pull/2215#issuecomment-2862685453

   > I don't think there is much general value in providing "stack of chars" 
semantic. You can always provide these for your own projects through extension 
or category class.
   
   @eric-milles ,
   the issue try to solve the basic Use Case String:
   -  Useful in algorithms where you need to modify strings dynamically, such 
as backtracking or parsing tasks.
   
   given some examples code here: 
https://issues.apache.org/jira/browse/GROOVY-11655




> Create extension method to make StringBuilder like a stack
> ----------------------------------------------------------
>
>                 Key: GROOVY-11655
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11655
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: John Dong
>            Priority: Major
>
> for leetcode problem: 
> [https://leetcode.com/problems/design-a-text-editor/description/]
> the java code below,  suppose StringBuilder to be a contain of chars , 
> meanwhile as a stack.
>  
> {code:java}
> class TextEditor {
>     private final StringBuilder left = new StringBuilder(); 
>     private final StringBuilder right = new StringBuilder(); 
>     public void addText(String text) {
>         left.append(text); 
>     }
>     public int deleteText(int k) {
>         k = Math.min(k, left.length());
>         left.setLength(left.length() - k); 
>         return k;
>     }
>     public String cursorLeft(int k) {
>         while (k > 0 && !left.isEmpty()) {
>             right.append(left.charAt(left.length() - 1)); 
>             left.setLength(left.length() - 1);
>             k--;
>         }
>         return text();
>     }
>     public String cursorRight(int k) {
>         while (k > 0 && !right.isEmpty()) {
>             left.append(right.charAt(right.length() - 1)); 
>             right.setLength(right.length() - 1);
>             k--;
>         }
>         return text();
>     }
>     private String text() {
>         
>         return left.substring(Math.max(left.length() - 10, 0));
>     }
> }
> {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to