<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    First they ignore you
    then they ridicule you
    then they fight you
    then you win
        -- Mahatma Gandhi
    Chinese => English     英文 => 中文             
    隨筆-221  評論-1047  文章-0  trackbacks-0
    今天看到迅雷的一個筆試題,一時手癢,便拿來試試,具體題目是這樣的:
    請打印出一個字符串中所有字母的全排列結果,比如輸入字符串abc,則打印出abc, acb, bac, bca, cab, cba

    下面是我的解法,由于時間倉促,沒有仔細研究,無法保證這是最優的

    package ?edu.ecust.test;

    import ?java.util.ArrayList;
    import ?java.util.Iterator;
    import ?java.util.List;

    public ? class ?Test? {
    ????
    public ? static ? void ?main(String[]?args)? {
    ????????System.out.println(range(
    " abc " ));
    ????}

    ????
    ????
    public ? static ?List < String > ?range(String?str)? {
    ????????
    if ?( 1 ? == ?str.length())? {
    ????????????List
    < String > ?result? = ? new ?ArrayList < String > ();
    ????????????result.add(str);
    ????????????
    return ?result;
    ????????}

    ????????
    ????????
    char []?chars? = ?str.toCharArray();
    ????????
    ????????List
    < String > ?result? = ? new ?ArrayList < String > ();
    ????????
    for ?( int ?i? = ? 0 ,?n? = ?chars.length;?i? < ?n;?i ++ )? {
    ????????????
    char []?swapedChars? = ?swapElems(i,?chars);
    ????????????
    char ?c? = ?swapedChars[ 0 ];
    ????????????
    char []?remainChars? = ? new ? char [swapedChars.length? - ? 1 ];
    ????????????System.arraycopy(swapedChars,?
    1 ,?remainChars,? 0 ,?swapedChars.length? - ? 1 );
    ????????????String?remainStr?
    = ? new ?String(remainChars);
    ????????????List
    < String > ?partialResult? = ?range(remainStr);
    ????????????
    ????????????
    for ?(Iterator < String > ?it? = ?partialResult.iterator();?it.hasNext();?)? {
    ????????????????result.add(c?
    + ?it.next());
    ????????????}

    ????????}

    ????????
    ????????
    return ?result;
    ????}

    ????
    ????
    public ? static ? char []?swapElems( int ?index,? char []?array)? {
    ????????
    char []?chars? = ? new ? char [array.length];
    ????????System.arraycopy(array,?
    0 ,?chars,? 0 ,?array.length);
    ????????
    char ?c? = ?chars[index];
    ????????
    for ?( int ?i? = ?index? - ? 1 ;?i? >= ? 0 ;?i -- )? {
    ????????????chars[i?
    + ? 1 ]? = ?chars[i];
    ????????}

    ????????chars[
    0 ]? = ?c;
    ????????
    return ?chars;
    ????}

    }
    posted on 2006-11-03 19:07 山風小子 閱讀(3094) 評論(5)  編輯  收藏 所屬分類: Algorithm
    主站蜘蛛池模板: 亚洲一卡一卡二新区无人区| 亚洲邪恶天堂影院在线观看| 亚洲欧美成aⅴ人在线观看| 曰批全过程免费视频网址| 亚洲AV综合色区无码一区| 亚洲精品偷拍视频免费观看| 亚洲JIZZJIZZ中国少妇中文| 男男gvh肉在线观看免费| 国产又粗又长又硬免费视频| 亚洲av无码一区二区三区在线播放| 女人张腿给男人桶视频免费版| 亚洲综合一区二区三区四区五区| 91免费精品国自产拍在线不卡| 中文文字幕文字幕亚洲色| 四虎成人免费大片在线| 亚洲国产欧洲综合997久久| 国产乱人免费视频| 一区二区三区视频免费观看| 亚洲一区二区三区AV无码| 免费精品久久天干天干| 亚洲视频免费在线看| 1024免费福利永久观看网站| 亚洲色在线无码国产精品不卡| 女人18毛片免费观看| 特级毛片A级毛片100免费播放| 亚洲精品国产自在久久| 国产拍拍拍无码视频免费| 91天堂素人精品系列全集亚洲| 91香蕉成人免费网站| 色综合久久精品亚洲国产| 亚洲色偷拍另类无码专区| 久草免费手机视频| 中文字幕在线观看亚洲日韩| 全黄性性激高免费视频| 中文字幕不卡免费视频| 亚洲婷婷在线视频| va亚洲va日韩不卡在线观看| 免费观看久久精彩视频| 亚洲人成网站18禁止| 亚洲精品成人片在线观看精品字幕| 2020因为爱你带字幕免费观看全集|