JavaScript/String/面试题:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 输出字符串 == 之前微软小冰创始团队的一个大佬面试笔试,题目如下: <syntaxhighlight lang="javascript"> /** Problem: Longest continous…”
 
Kangkk​(留言 | 贡献)
小 文字替换 -“{{leftrightflex|”替换为“{{Double-columns|”
标签:ReplaceText 移动版编辑 移动版网页编辑
 
(未显示同一用户的3个中间版本)
第1行: 第1行:
== 输出字符串 ==
== 输出字符串 ==
<!--
之前微软小冰创始团队的一个大佬面试笔试,题目如下:
之前微软小冰创始团队的一个大佬面试笔试,题目如下:
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
第199行: 第200行:
processor.process();</syntaxhighlight>
processor.process();</syntaxhighlight>
但是不符合题目求,然后改正:
但是不符合题目求,然后改正:
{{leftrightflex|<syntaxhighlight
{{Double-columns|<syntaxhighlight
lang="javascript">
lang="javascript">
/**
Problem: Longest continous valid substring
Your task is to find the longest continous substrings
consists of only "valid" characters for each line and
output the substring as a separate line to output.
Here "valid" is defined as English letters (upper and
lower cases) and space.
Here is an example of two lines of input stream:
^%oA i923diuo
(989872347897*&&:":}{?>
And the ouput stream should also be two lines:
oA i
Please note that the output lines should be in the
exact same order as their input lines and the number
of input lines and output lines should be the same.
InStream and OutStream are two already implemented
interfaces for input and output respectively. You should use them for I/O and they have only the methods
defined below. Don't read their implementations, which
are not relevant to this interview.
TWO TASKs:
1. add enough (according to you) test cases in line 52.
2. implement LongestValidSubstrings() of Processor class
ADDITIONAL REQUIREMENTS:
Do not use regular expression.
Use as little memory as you can.
You may search on the web freely when you code.
If any questions please contact me.
*/
/**
* The interface for input
*
* Only sequential access allowed. Cannot get length information.
*
* Note:
*    Ask question if anything is not clear.
*    The implementations are just mock. Your code should not depend on them.
*/
class InStream
class InStream
{
{
第358行: 第312行:
         count = 0
         count = 0
       }
       }
      //  if(!this.isOk(line[index])||((Number(index)+1===line.length)&&this.isOk(line[index])))
//      if(Number(index)+1===line.length){
//        if(sign&&len<count){
//            //start = index - count
//            len = count
//        }
//        count = 0
//        sign = false
//      }
     }
     }
     this.outStream.writeBuffer(line.slice(start, start+len)+'\n')
     this.outStream.writeBuffer(line.slice(start, start+len)+'\n')
  // this.outStream.writeBuffer(arr+'\n')
//    let resultArr = [...new Set(arr)].filter(function (s) {
//      return s && s.trim();
//    });
//    if(!this.isSpaceArray(resultArr)){
//      for(let i=0;i<resultArr.length;i++){
//        this.outStream.writeBuffer(resultArr[i])
//      }
//    }
   }
   }
}
}
第391行: 第326行:
dfvsdcs
dfvsdcs
</pre>}}}}
</pre>}}}}
然后笔试通过了,心满意足~
-->

2026年11月26日 (四) 08:18的最新版本

输出字符串