锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲av无码专区在线观看下载 ,日韩精品亚洲专区在线影视,亚洲午夜未满十八勿入网站2http://www.tkk7.com/sandy/archive/2013/05/22/399605.html灝忔槑灝忔槑Wed, 22 May 2013 14:25:00 GMThttp://www.tkk7.com/sandy/archive/2013/05/22/399605.htmlhttp://www.tkk7.com/sandy/comments/399605.htmlhttp://www.tkk7.com/sandy/archive/2013/05/22/399605.html#Feedback0http://www.tkk7.com/sandy/comments/commentRss/399605.htmlhttp://www.tkk7.com/sandy/services/trackbacks/399605.html
Problem

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = "great":
    great
   /    \
  gr    eat
 / \    /  \
g   r  e   at
           / \
          a   t
To scramble the string, we may choose any non-leaf node and swap its two children.
For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat".
    rgeat
   /    \
  rg    eat
 / \    /  \
r   g  e   at
           / \
          a   t
We say that "rgeat" is a scrambled string of "great".
Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a scrambled string "rgtae".
    rgtae
   /    \
  rg    tae
 / \    /  \
r   g  ta  e
       / \
      t   a
We say that "rgtae" is a scrambled string of "great".
Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.

 


鍒嗘瀽錛?br />
榪欎釜闂鏄痝oogle鐨勯潰璇曢銆傜敱浜庝竴涓瓧絎︿覆鏈夊緢澶氱浜屽弶琛ㄧず娉曪紝璨屼技寰堥毦鍒ゆ柇涓や釜瀛楃涓叉槸鍚﹀彲浠ュ仛榪欐牱鐨勫彉鎹€?br />瀵逛粯澶嶆潅闂鐨勬柟娉曟槸浠庣畝鍗曠殑鐗逛緥鏉ユ濊冿紝浠庤屾壘鍑鴻寰嬨?br />鍏堣冨療綆鍗曟儏鍐碉細
瀛楃涓查暱搴︿負1錛氬緢鏄庢樉錛屼袱涓瓧絎︿覆蹇呴』瀹屽叏鐩稿悓鎵嶅彲浠ャ?br />瀛楃涓查暱搴︿負2錛氬綋s1="ab", s2鍙湁"ab"鎴栬?ba"鎵嶅彲浠ャ?br />瀵逛簬浠繪剰闀垮害鐨勫瓧絎︿覆錛屾垜浠彲浠ユ妸瀛楃涓瞫1鍒嗕負a1,b1涓や釜閮ㄥ垎錛宻2鍒嗕負a2,b2涓や釜閮ㄥ垎錛屾弧瓚籌紙(a1~a2) && (b1~b2)錛夋垨鑰?nbsp;錛?a1~b2) && (a1~b2)錛?br />
濡傛錛屾垜浠壘鍒頒簡瑙e喅闂鐨勬濊礬銆傞鍏堟垜浠皾璇曠敤閫掑綊鏉ュ啓銆?br />

瑙f硶涓錛堥掑綊錛?br />
涓や釜瀛楃涓茬殑鐩鎬技鐨勫繀澶囨潯浠舵槸鍚湁鐩稿悓鐨勫瓧絎﹂泦銆傜畝鍗曠殑鍋氭硶鏄妸涓や釜瀛楃涓茬殑瀛楃鎺掑簭鍚庯紝鐒跺悗姣旇緝鏄惁鐩稿悓銆?br />鍔犱笂榪欎釜媯鏌ュ氨鍙互澶уぇ鐨勫噺灝戦掑綊嬈℃暟銆?br />浠g爜濡備笅錛?br />
public boolean isScramble(String s1, String s2) {
        int l1 = s1.length();
        int l2 = s2.length();
        if(l1!=l2){
            return false;
        }
        if(l1==0){
            return true;
        }
        
        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        if(l1==1){
            return c1[0]==c2[0];
        }
        Arrays.sort(c1);
        Arrays.sort(c2);
        for(int i=0;i<l1;++i){
            if(c1[i]!=c2[i]){
                return false;
            }
        }
        
        boolean result = false;
        for(int i=1;i<l1 && !result;++i){
            String s11 = s1.substring(0,i);
            String s12 = s1.substring(i);
            String s21 = s2.substring(0,i);
            String s22 = s2.substring(i);
            result = isScramble(s11,s21) && isScramble(s12,s22);
            if(!result){
                String s31 = s2.substring(0,l1-i);
                String s32 = s2.substring(l1-i);
                result = isScramble(s11,s32) && isScramble(s12,s31);
            }
        }
        
        return result;
    }

瑙f硶浜岋紙鍔ㄦ佽鍒掞級
鍑忓皯閲嶅璁$畻鐨勬柟娉曞氨鏄姩鎬佽鍒掋傚姩鎬佽鍒掓槸涓縐嶇濂囩殑綆楁硶鎶鏈紝涓嶄翰鑷幓鍐欙紝鏄緢闅懼畬鍏ㄦ帉鎻″姩鎬佽鍒掔殑銆?br />
榪欓噷鎴戜嬌鐢ㄤ簡涓涓笁緇存暟緇刡oolean result[len][len][len],鍏朵腑絎竴緇翠負瀛愪覆鐨勯暱搴︼紝絎簩緇翠負s1鐨勮搗濮嬬儲寮曪紝絎笁緇翠負s2鐨勮搗濮嬬儲寮曘?br />result[k][i][j]琛ㄧずs1[i...i+k]鏄惁鍙互鐢眘2[j...j+k]鍙樺寲寰楁潵銆?br />
浠g爜濡備笅錛岄潪甯哥畝媧佷紭緹庯細

public class Solution {
    public boolean isScramble(String s1, String s2) {
        int len = s1.length();
        if(len!=s2.length()){
            return false;
        }
        if(len==0){
            return true;
        }
        
        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        
        boolean[][][] result = new boolean[len][len][len];
        for(int i=0;i<len;++i){
            for(int j=0;j<len;++j){
                result[0][i][j] = (c1[i]==c2[j]);
            }
        }
        
        for(int k=2;k<=len;++k){
            for(int i=len-k;i>=0;--i){
              for(int j=len-k;j>=0;--j){
                  boolean r = false;
                  for(int m=1;m<k && !r;++m){
                      r = (result[m-1][i][j] && result[k-m-1][i+m][j+m]) || (result[m-1][i][j+k-m] && result[k-m-1][i+m][j]);
                  }
                  result[k-1][i][j] = r;
              }
            }
        }
        
        return result[len-1][0][0];
    }
}


灝忔槑 2013-05-22 22:25 鍙戣〃璇勮
]]>
Subsetshttp://www.tkk7.com/sandy/archive/2013/05/21/399521.html灝忔槑灝忔槑Tue, 21 May 2013 14:50:00 GMThttp://www.tkk7.com/sandy/archive/2013/05/21/399521.htmlhttp://www.tkk7.com/sandy/comments/399521.htmlhttp://www.tkk7.com/sandy/archive/2013/05/21/399521.html#Feedback0http://www.tkk7.com/sandy/comments/commentRss/399521.htmlhttp://www.tkk7.com/sandy/services/trackbacks/399521.html
Problem

Given a collection of integers that might contain duplicates, S, return all possible subsets.

Note:

  • Elements in a subset must be in non-descending order.
  • The solution set must not contain duplicate subsets.

For example,
If S = [1,2,2], a solution is:

[   [2],   [1],   [1,2,2],   [2,2],   [1,2],   [] ] 

鍒嗘瀽錛?br />鍥犱負瑕佹眰緇撴灉闆嗘槸鍗囧簭鎺掑垪錛屾墍浠ラ鍏堟垜浠瀵規暟緇勮繘琛屾帓搴忋?br />
瀛愰泦鐨勯暱搴﹀彲浠ヤ粠0鍒版暣涓暟緇勭殑闀垮害銆傞暱搴︿負n+1鐨勫瓙闆嗗彲浠ョ敱闀垮害涓簄鐨勫瓙闆嗗啀鍔犱笂鍦ㄤ箣鍚庣殑涓涓厓绱犵粍鎴愩?br />
榪欓噷鎴戜嬌鐢ㄤ簡涓変釜鎶宸?br />1銆備嬌鐢ㄤ簡涓涓猧ndex鏁扮粍鏉ヨ褰曟瘡涓瓙闆嗙殑鏈澶х儲寮曪紝榪欐牱娣誨姞鏂板厓绱犲氨寰堢畝鍗曘?br />2銆備嬌鐢ㄤ簡涓や釜鍙橀噺start鍜宔nd鏉ヨ褰曚笂涓涓暱搴︾殑瀛愰泦鍦ㄧ粨鏋滀腑鐨勮搗濮嬪拰緇堟浣嶇疆銆?br />3銆傚幓閲嶅鐞嗕嬌鐢ㄤ簡涓涓猯ast鍙橀噺璁板綍鍓嶄竴嬈$殑鍊鹼紝瀹冪殑鍒濆鍊艱涓篠[0]-1,榪欐牱灝變繚璇佷簡鍜屾暟緇勭殑浠諱綍涓涓厓绱犱笉鍚屻?br />
浠g爜濡備笅錛?br />
public class Solution {
    public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] S) {
        Arrays.sort(S);
        
        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
        ArrayList<Integer> indexs = new ArrayList<Integer>();
        result.add(new ArrayList<Integer>());
        indexs.add(-1);
        
        int slen = S.length;
        int start=0,end=0;
        for(int len=1;len<=slen;++len){
            int e = end;
            for(int i=start;i<=end;++i){
                ArrayList<Integer> ss = result.get(i);
                int index = indexs.get(i).intValue();
                int last = S[0]-1;
                for(int j = index+1;j<slen;++j){
                    int v = S[j];
                    if(v!=last){
                        ArrayList<Integer> newss = new ArrayList<Integer>(ss);
                        newss.add(v);
                        result.add(newss);
                        indexs.add(j);
                        ++e;
                        last = v;
                    }
                }
            }
            
            start = end+1;
            end = e;
        }
        return result;
    }
}


灝忔槑 2013-05-21 22:50 鍙戣〃璇勮
]]>
鏍奸浄鐮?/title><link>http://www.tkk7.com/sandy/archive/2013/05/20/399526.html</link><dc:creator>灝忔槑</dc:creator><author>灝忔槑</author><pubDate>Mon, 20 May 2013 13:09:00 GMT</pubDate><guid>http://www.tkk7.com/sandy/archive/2013/05/20/399526.html</guid><wfw:comment>http://www.tkk7.com/sandy/comments/399526.html</wfw:comment><comments>http://www.tkk7.com/sandy/archive/2013/05/20/399526.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/sandy/comments/commentRss/399526.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sandy/services/trackbacks/399526.html</trackback:ping><description><![CDATA[<div><fieldset><legend>闂</legend>鏍奸浄鐮佹槸涓涓簩榪涘埗鐨勭紪鐮佺郴緇燂紝鐩擱偦鐨勪袱涓暟鍙湁涓浣嶆槸涓嶅悓鐨勩?br />緇欏畾涓涓潪璐熺殑鏁存暟n錛屼唬琛ㄤ簡鏍奸浄鐮佺殑浣嶇殑鎬繪暟銆傝緭鍑烘牸闆風爜鐨勫簭鍒楋紝榪欎釜搴忓垪蹇呴』浠?寮濮嬨?br /><br />姣斿錛岀粰瀹歯=2,杈撳嚭錛?錛?錛?錛?錛斤紝鏍奸浄鐮佹槸<br />0 錛?00<br />1 錛?01<br />3 錛?11<br />2 錛?10<br /><br />娉細鏍奸浄鐮佺殑搴忓垪騫朵笉鏄敮涓錛屾瘮濡俷=2鏃訛紝錛?錛?錛?錛?錛戒篃婊¤凍鏉′歡銆?br /></fieldset><br /><br />鍒嗘瀽錛?br />鏍奸浄鐮佺殑搴忓垪涓簲鍖呭惈2^n涓暟銆傝繖涓棶棰樺垵鐪嬭搗鏉ヤ笉瀹規槗錛屾垜浠鎯沖嚭涓涓敓鎴愭柟娉曘?br /><br />瀵逛簬n=2,搴忓垪鏄細<br />00錛?1錛?1錛?0<br />閭e浜巒=3,濡備綍鍒╃敤n=2鐨勫簭鍒楀憿錛熶竴涓柟娉曟槸錛屽厛鍦╪=2鐨勫洓涓簭鍒楀墠鍔?錛堣繖鍏跺疄鏄繚鎸佷笉鍙橈級錛岀劧鍚庡啀鑰冭檻鎶婃渶楂樹綅鍙樻垚1錛屽彧闇瑕佹妸鏂瑰悜鍙嶈繃鏉ュ氨鍙互浜?br />000錛?01錛?11錛?10<br />100錛?01錛?11錛?10錛?gt; 110,111,101,100<br />鎶婅繖涓よ鍚堣搗鏉ュ氨鍙互寰楀埌鏂扮殑搴忓垪銆?br /><br />鎯抽氫簡錛屽啓浠g爜灝卞緢瀹規槗浜嗐?br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> Solution {<br />    <span style="color: #0000FF; ">public</span> ArrayList<Integer> grayCode(<span style="color: #0000FF; ">int</span> n) {<br />        ArrayList<Integer> result = <span style="color: #0000FF; ">new</span> ArrayList<Integer>();<br />        result.add(0);<br />        <span style="color: #0000FF; ">if</span>(n>0){<br />            result.add(1);<br />        }<br />        <br />        <span style="color: #0000FF; ">int</span> mask = 1;<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=2;i<=n;++i){<br />            mask *= 2;<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=result.size()-1;j>=0;--j){<br />                <span style="color: #0000FF; ">int</span> v = result.get(j).intValue();<br />                v |= mask;<br />                result.add(v);<br />            }<br />        }<br />        <span style="color: #0000FF; ">return</span> result;<br />    }<br />}</div></div><img src ="http://www.tkk7.com/sandy/aggbug/399526.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sandy/" target="_blank">灝忔槑</a> 2013-05-20 21:09 <a href="http://www.tkk7.com/sandy/archive/2013/05/20/399526.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>浜ゅ弶瀛楃涓?/title><link>http://www.tkk7.com/sandy/archive/2013/05/10/398754.html</link><dc:creator>灝忔槑</dc:creator><author>灝忔槑</author><pubDate>Fri, 10 May 2013 12:47:00 GMT</pubDate><guid>http://www.tkk7.com/sandy/archive/2013/05/10/398754.html</guid><wfw:comment>http://www.tkk7.com/sandy/comments/398754.html</wfw:comment><comments>http://www.tkk7.com/sandy/archive/2013/05/10/398754.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.tkk7.com/sandy/comments/commentRss/398754.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sandy/services/trackbacks/398754.html</trackback:ping><description><![CDATA[<div><fieldset><legend>闂</legend>緇欏畾瀛楃涓瞫1,s2,s3,鍒ゆ柇s3鏄惁鍙互鐢眘1鍜宻2浜ゅ弶緇勬垚寰楀埌銆?br /><br />渚嬪錛?br /><br /><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 13px; vertical-align: baseline; color: #222222; font-family: 'Helvetica Neue', arial, sans-serif; "><em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; ">s1</em> = <code style="margin: 0px; padding: 1px 5px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">"aabcc"</code>,<br style="margin: 0px; " /><em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; ">s2</em> = <code style="margin: 0px; padding: 1px 5px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">"dbbca"</code>,</p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 13px; vertical-align: baseline; color: #222222; font-family: 'Helvetica Neue', arial, sans-serif; ">When <em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; ">s3</em> = <code style="margin: 0px; padding: 1px 5px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">"aadbbcbcac"</code>, return true.<br style="margin: 0px; " />When <em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; ">s3</em> = <code style="margin: 0px; padding: 1px 5px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">"aadbbbaccc"</code>, return false.</p></fieldset><br />瑙f硶涓錛氾紙閫掑綊錛?br /><br />涓涓畝鍗曠殑鎯蟲硶錛屾槸閬嶅巻s3鐨勬瘡涓瓧絎︼紝榪欎釜瀛楃蹇呴』絳変簬s1鍜宻2鐨勬煇涓瓧絎︺傚鏋滈兘涓嶇浉絳夛紝鍒欒繑鍥瀎alse<br />鎴戜滑浣跨敤3涓彉閲廼,j,k鍒嗗埆璁板綍褰撳墠s1,s2,s3鐨勫瓧絎︿綅緗?br />濡傛灉s3[k] = s1[i], i鍚戝悗縐誨姩涓浣嶃傚鏋渟3[k]=s2[j],j鍚戝悗縐誨姩涓浣嶃?br />榪欎釜棰樼洰涓昏闅懼湪濡傛灉s1鍜宻2鐨勫瓧絎﹀嚭鐜伴噸澶嶇殑鏃跺欙紝灝辨湁涓ょ鎯呭喌錛宨,j閮藉彲浠ュ悜鍚庝竴浣嶃?br />涓嬮潰鐨勭畻娉曞湪榪欑鎯呭喌浣跨敤浜嗛掑綊錛屽緢綆鍗曠殑鍋氭硶銆備絾鏄晥鐜囬潪甯稿樊錛屾槸鎸囨暟澶嶆潅搴︾殑銆?br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> Solution {<br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">boolean</span> isInterleave(String s1, String s2, String s3) {<br />        <span style="color: #0000FF; ">int</span> l1 = s1.length();<br />        <span style="color: #0000FF; ">int</span> l2 = s2.length();<br />        <span style="color: #0000FF; ">int</span> l3 = s3.length();<br />        <br />        <span style="color: #0000FF; ">if</span>(l1+l2!=l3){<br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />        }<br />        <br />        <span style="color: #0000FF; ">char</span>[] c1 = s1.toCharArray();<br />        <span style="color: #0000FF; ">char</span>[] c2 = s2.toCharArray();<br />        <span style="color: #0000FF; ">char</span>[] c3 = s3.toCharArray();<br />        <br />        <span style="color: #0000FF; ">int</span> i=0,j=0;<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> k=0;k<l3;++k){<br />            <span style="color: #0000FF; ">char</span> c = c3[k];<br />            <span style="color: #0000FF; ">boolean</span> m1 = i<l1 && c==c1[i];<br />            <span style="color: #0000FF; ">boolean</span> m2 = j<l2 && c==c2[j];<br />            <span style="color: #0000FF; ">if</span>(!m1 && !m2){<br />                <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />            }<br />            <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(m1 && m2){<br />                String news3 =  s3.substring(k+1);<br />                <span style="color: #0000FF; ">return</span> isInterleave(s1.substring(i+1),s2.substring(j),news3)<br />                                || isInterleave(s1.substring(i),s2.substring(j+1),news3);<br />            }<br />            <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(m1){<br />                ++i;<br />            }<br />            <span style="color: #0000FF; ">else</span>{<br />                ++j;<br />            }<br />        }<br />        <br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;        <br />    }<br />}</div><br /><br />瑙f硶浜岋細錛堝姩鎬佽鍒掞級<br />涓轟簡鍑忓皯閲嶅璁$畻錛屽氨瑕佷嬌鐢ㄥ姩鎬佽鍒掓潵璁板綍涓棿緇撴灉銆?br /><br />榪欓噷鎴戜嬌鐢ㄤ簡涓涓簩緇存暟緇剅esult[i][j]鏉ヨ〃紺簊1鐨勫墠i涓瓧絎﹀拰s2鐨勫墠j涓瓧絎︽槸鍚﹁兘鍜宻3鐨勫墠i+j涓瓧絎﹀尮閰嶃?br /><br />鐘舵佽漿縐繪柟紼嬪涓嬶細<br />result[i,j] = (result[i-1,j] && s1[i] = s3[i+j])  || (result[i,j-1] && s2[j] = s3[i+j]);<br />鍏朵腑0≤i≤len(s1) ,0≤j≤len(s2)</div><div><br />榪欐牱綆楁硶澶嶆潅搴﹀氨浼氫笅闄嶅埌O(l1*l2)<br /></div><div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> Solution {<br />   <br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">boolean</span> isInterleave(String s1, String s2, String s3) {<br />        <span style="color: #0000FF; ">int</span> l1 = s1.length();<br />        <span style="color: #0000FF; ">int</span> l2 = s2.length();<br />        <span style="color: #0000FF; ">int</span> l3 = s3.length();<br />       <br />        <span style="color: #0000FF; ">if</span>(l1+l2!=l3){<br />            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />        }<br />        <br />        <span style="color: #0000FF; ">char</span>[] c1 = s1.toCharArray();<br />        <span style="color: #0000FF; ">char</span>[] c2 = s2.toCharArray();<br />        <span style="color: #0000FF; ">char</span>[] c3 = s3.toCharArray();<br />        <br />        <span style="color: #0000FF; ">boolean</span>[][] result = <span style="color: #0000FF; ">new</span> <span style="color: #0000FF; ">boolean</span>[l1+1][l2+1];<br />        result[0][0] = <span style="color: #0000FF; ">true</span>;<br />        <br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<l1;++i){<br />            <span style="color: #0000FF; ">if</span>(c1[i]==c3[i]){<br />                result[i+1][0] = <span style="color: #0000FF; ">true</span>;<br />            }<br />            <span style="color: #0000FF; ">else</span>{<br />                <span style="color: #0000FF; ">break</span>;<br />            }<br />        }<br />        <br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<l2;++j){<br />            <span style="color: #0000FF; ">if</span>(c2[j]==c3[j]){<br />                result[0][j+1] = <span style="color: #0000FF; ">true</span>;<br />            }<br />            <span style="color: #0000FF; ">else</span>{<br />                <span style="color: #0000FF; ">break</span>;<br />            }<br />        }<br />        <br />        <br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<=l1;++i){<br />            <span style="color: #0000FF; ">char</span> ci = c1[i-1];<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=1;j<=l2;++j){<br />                <span style="color: #0000FF; ">char</span> cj = c2[j-1];<br />                <span style="color: #0000FF; ">char</span> ck = c3[i+j-1];<br />                   result[i][j] = (result[i][j-1] && cj==ck) || (result[i-1][j] && ci==ck);<br />            }<br />        }<br />        <br />        <span style="color: #0000FF; ">return</span> result[l1][l2];<br />   }<br />}</div></div><img src ="http://www.tkk7.com/sandy/aggbug/398754.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sandy/" target="_blank">灝忔槑</a> 2013-05-10 20:47 <a href="http://www.tkk7.com/sandy/archive/2013/05/10/398754.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>涓変釜鏁頒箣鍜?/title><link>http://www.tkk7.com/sandy/archive/2013/05/01/398604.html</link><dc:creator>灝忔槑</dc:creator><author>灝忔槑</author><pubDate>Wed, 01 May 2013 15:13:00 GMT</pubDate><guid>http://www.tkk7.com/sandy/archive/2013/05/01/398604.html</guid><wfw:comment>http://www.tkk7.com/sandy/comments/398604.html</wfw:comment><comments>http://www.tkk7.com/sandy/archive/2013/05/01/398604.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/sandy/comments/commentRss/398604.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sandy/services/trackbacks/398604.html</trackback:ping><description><![CDATA[     鎽樿: 緇欏畾涓涓敱n涓暣鏁扮粍鎴愮殑鏁扮粍S錛屾槸鍚﹀瓨鍦⊿涓殑涓変釜鏁癮,b,c浣垮緱 a+b+c=0?鎵懼嚭鎵鏈夌殑涓嶉噸澶嶇殑鍜屼負0鐨勪笁鍏冪粍銆?<br> <br>娉ㄦ剰錛?<br>1.涓夊厓緇勭殑鏁存暟鎸夌収鍗囧簭鎺掑垪 a<b<c <br>2.緇欏嚭鐨勭粨鏋滀腑涓嶈兘鍚湁鐩稿悓鐨勪笁鍏冪粍  <a href='http://www.tkk7.com/sandy/archive/2013/05/01/398604.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/sandy/aggbug/398604.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sandy/" target="_blank">灝忔槑</a> 2013-05-01 23:13 <a href="http://www.tkk7.com/sandy/archive/2013/05/01/398604.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>瀛愬簭鍒楄鏁?/title><link>http://www.tkk7.com/sandy/archive/2013/04/26/398467.html</link><dc:creator>灝忔槑</dc:creator><author>灝忔槑</author><pubDate>Fri, 26 Apr 2013 15:33:00 GMT</pubDate><guid>http://www.tkk7.com/sandy/archive/2013/04/26/398467.html</guid><wfw:comment>http://www.tkk7.com/sandy/comments/398467.html</wfw:comment><comments>http://www.tkk7.com/sandy/archive/2013/04/26/398467.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/sandy/comments/commentRss/398467.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sandy/services/trackbacks/398467.html</trackback:ping><description><![CDATA[     鎽樿: 緇欏畾涓や釜瀛楃涓睸鍜孴錛岃綆桽鐨勫瓙搴忓垪涓篢鐨勪釜鏁般?<br> <br>榪欓噷鐨勫瓧絎︿覆鐨勫瓙搴忓垪鎸囩殑鏄垹闄ゅ瓧絎︿覆鐨勫嚑涓瓧絎︼紙涔熷彲浠ヤ笉鍒狅級鑰屽緱鍒扮殑鏂扮殑瀛楃涓詫紝浣嗘槸涓嶈兘鏀瑰彉瀛楃鐨勭浉瀵逛綅緗?<br> <br>姣斿鈥淎CE鈥濇槸鈥淎BCDE鈥濈殑瀛愬簭鍒楋紝浣嗘槸鈥淎EC鈥濆氨涓嶆槸銆?<br> <br>濡傛灉S錛濃渞abbbit鈥?T錛濃渞abit鈥濓紝鏈?縐嶄笉鍚岀殑瀛愬簭鍒椾負T鐨勬瀯鎴愭柟娉曪紝閭d箞緇撴灉搴旇榪斿洖3銆?nbsp; <a href='http://www.tkk7.com/sandy/archive/2013/04/26/398467.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/sandy/aggbug/398467.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sandy/" target="_blank">灝忔槑</a> 2013-04-26 23:33 <a href="http://www.tkk7.com/sandy/archive/2013/04/26/398467.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>璁劇疆浜屽弶鏍戠殑next鑺傜偣http://www.tkk7.com/sandy/archive/2013/04/26/398413.html灝忔槑灝忔槑Fri, 26 Apr 2013 03:23:00 GMThttp://www.tkk7.com/sandy/archive/2013/04/26/398413.htmlhttp://www.tkk7.com/sandy/comments/398413.htmlhttp://www.tkk7.com/sandy/archive/2013/04/26/398413.html#Feedback0http://www.tkk7.com/sandy/comments/commentRss/398413.htmlhttp://www.tkk7.com/sandy/services/trackbacks/398413.html
闂緇欏畾涓棰椾簩鍙夋爲錛?br />
class TreeLinkNode {
  TreeLinkNode left;
  TreeLinkNode right;
  TreeLinkNode next;
}
瑕佹眰鎶婃墍鏈夎妭鐐圭殑next鑺傜偣璁劇疆鎴愬畠鍙寵竟鐨勮妭鐐癸紝濡傛灉娌℃湁鍙寵妭鐐癸紝璁劇疆鎴愮┖銆傚垵濮嬬姸鎬侊紝鎵鏈夌殑next鐨勬寚閽堝潎涓簄ull.

瑕佹眰:浣犲彧鑳戒嬌鐢ㄥ父鏁扮殑絀洪棿銆?br />
姣斿錛?br />
         1
       /  \
      2    3
     / \    \
    4   5    7
搴旇杈撳嚭錛?br />
1 -> NULL
       /  \
      2 -> 3 -> NULL
     / \    \
    4-> 5 -> 7 -> NULL

鍒嗘瀽錛?br />棰樼洰涓嶉毦錛屼絾鏄湪闈㈣瘯鏃訛紝鍦ㄦ湁闄愮殑鏃墮棿鍐咃紝娌℃湁bug鍐欏嚭錛岃繕鏄緢鑰冮獙鍔熷姏鐨勩?br />
瑙e喅榪欎釜闂鐨勬濊礬鏄愬眰鎵弿錛屼笂涓灞傝緗ソ涓嬩竴灞傜殑next鍏崇郴錛屽湪澶勭悊絀烘寚閽堢殑鏃跺欒鏍煎灝忓績銆?br />浠g爜濡備笅錛屾湁娉ㄩ噴錛屽簲璇ュ緢瀹規槗鐪嬫噦錛?br />浣跨敤浜嗕笁涓寚閽堬細
node:褰撳墠鑺傜偣
firstChild:涓嬩竴灞傜殑絎竴涓潪絀哄瓙鑺傜偣
lastChild:涓嬩竴灞傜殑鏈鍚庝竴涓緟澶勭悊錛堟湭璁劇疆next)鐨勫瓙鑺傜偣

    public void connect(TreeLinkNode root) {
        TreeLinkNode node = root;
        TreeLinkNode firstChild = null;
        TreeLinkNode lastChild = null;
        
        while(node!=null){
            if(firstChild == null){ //璁板綍絎竴涓潪絀哄瓙鑺傜偣
                firstChild = node.left!=null?node.left:node.right;
            }
            //璁劇疆瀛愯妭鐐圭殑next鍏崇郴錛?縐嶆儏鍐?/span>
            if(node.left!=null && node.right!=null){ 
                if(lastChild!=null){
                    lastChild.next = node.left;
                }
                node.left.next = node.right;
                lastChild = node.right;
            }
            else if(node.left!=null){
                if(lastChild!=null){
                    lastChild.next = node.left;
                }
                lastChild = node.left;
            }
            else if(node.right!=null){
                if(lastChild!=null){
                    lastChild.next = node.right;
                }
                lastChild = node.right;
            }
            //璁劇疆涓嬩竴涓妭鐐癸紝濡傛灉鏈眰宸茬粡閬嶅巻瀹屾瘯錛岀Щ鍒頒笅涓灞傜殑絎竴涓瓙鑺傜偣
            if(node.next!=null){
                node = node.next;
            }
            else{
                node = firstChild;
                firstChild = null;
                lastChild = null;
            }
        }
    }


灝忔槑 2013-04-26 11:23 鍙戣〃璇勮
]]>
鏈浣崇殑鑲$エ涔板崠鏃墮棿IIIhttp://www.tkk7.com/sandy/archive/2013/04/25/398406.html灝忔槑灝忔槑Thu, 25 Apr 2013 14:22:00 GMThttp://www.tkk7.com/sandy/archive/2013/04/25/398406.htmlhttp://www.tkk7.com/sandy/comments/398406.htmlhttp://www.tkk7.com/sandy/archive/2013/04/25/398406.html#Feedback0http://www.tkk7.com/sandy/comments/commentRss/398406.htmlhttp://www.tkk7.com/sandy/services/trackbacks/398406.html闂鍋囪浣犳湁涓涓暟緇勫寘鍚簡姣忓ぉ鐨勮偂紲ㄤ環鏍鹼紝瀹冪殑絎琲涓厓绱犲氨鏄i澶╃殑鑲$エ浠鋒牸銆?nbsp;

璁捐涓涓畻娉曞鎵炬渶澶х殑鏀剁泭銆備綘鍙互鏈澶氳繘琛屼袱嬈′氦鏄撱?br />娉ㄦ剰錛氫綘涓嶈兘鍚屾椂榪涜澶氭浜ゆ槗錛屼篃灝辨槸璇翠綘涔拌偂紲ㄤ箣鍓嶏紝蹇呴』鍗栨帀鎵嬩腑鑲$エ銆?/span>

鍒嗘瀽錛?br />榪欓亾棰樼浉姣斾箣鍓嶇殑涓ら亾棰橈紝闅懼害鎻愰珮浜嗕笉灝戙?br />
鍥犱負闄愬埗浜嗗彧鑳戒氦鏄撲袱嬈★紝鎵浠ユ垜浠彲浠ユ妸n澶╁垎涓轟袱孌碉紝鍒嗗埆璁$畻榪欎袱孌電殑鏈澶ф敹鐩婏紝灝卞彲浠ュ緱鍒頒竴涓渶澶ф敹鐩娿傜┓涓炬墍鏈夎繖鏍風殑鍒嗘硶錛屽氨鍙互寰楀埌鍏ㄥ眬鐨勬渶澶ф敹鐩娿?br />
涓轟簡鎻愰珮鏁堢巼錛岃繖閲屼嬌鐢ㄥ姩鎬佽鍒掞紝鍗蟲妸涓棿鐘舵佽褰曚笅鏉ャ備嬌鐢ㄤ簡涓や釜鏁扮粍profits錛宯profits鍒嗗埆璁板綍浠?..i鍜宨..n鐨勬渶澶ф敹鐩娿?br />
浠g爜濡備笅錛?br />
public int maxProfit(int[] prices) {
        int days = prices.length;
        if(days<2){
            return 0;
        }
        int[] profits = new int[days];
        int min = prices[0];
        int max = min;
        for(int i=1;i<days;++i){
            int p = prices[i];
            if(min>p){
                max = min = p;
            }
            else if(max<p){
                max = p;
            }
            int profit = max - min;
            profits[i] = (profits[i-1]>profit)?profits[i-1]:profit;
        }
        
        int[] nprofits = new int[days];
        nprofits[days-1] = 0;
        max = min = prices[days-1];
        for(int i=days-2;i>=0;--i){
            int p = prices[i];
            if(min>p){
                min =p;
            }
            else if(max<p){
                max = min = p;
            }
            int profit = max - min;
            nprofits[i] = (nprofits[i+1]>profit)?nprofits[i+1]:profit;
        }
        
        int maxprofit = 0;
        
        for(int i=0;i<days;++i){
            int profit = profits[i]+nprofits[i];
            if(maxprofit<profit){
                maxprofit = profit;
            }
        }
        
        return maxprofit;        
    }


灝忔槑 2013-04-25 22:22 鍙戣〃璇勮
]]>
鏈浣崇殑鑲$エ涔板崠鏃墮棿IIhttp://www.tkk7.com/sandy/archive/2013/04/19/398104.html灝忔槑灝忔槑Fri, 19 Apr 2013 13:50:00 GMThttp://www.tkk7.com/sandy/archive/2013/04/19/398104.htmlhttp://www.tkk7.com/sandy/comments/398104.htmlhttp://www.tkk7.com/sandy/archive/2013/04/19/398104.html#Feedback0http://www.tkk7.com/sandy/comments/commentRss/398104.htmlhttp://www.tkk7.com/sandy/services/trackbacks/398104.html
闂鍋囪浣犳湁涓涓暟緇勫寘鍚簡姣忓ぉ鐨勮偂紲ㄤ環鏍鹼紝瀹冪殑絎琲涓厓绱犲氨鏄i澶╃殑鑲$エ浠鋒牸銆?br />
璁捐涓涓畻娉曞鎵炬渶澶х殑鏀剁泭銆備綘鍙互榪涜浠繪剰澶氭浜ゆ槗銆備絾鏄紝浣犱笉鑳藉悓鏃惰繘琛屽嬈′氦鏄擄紝涔熷氨鏄浣犱拱鑲$エ涔嬪墠錛屽繀欏誨崠鎺夋墜涓偂紲ㄣ?/fieldset>
鍒嗘瀽錛氫負浜嗗緱鍒版渶澶ф敹鐩婏紝蹇呴』鍦ㄦ墍鏈変笂鍗囩殑鏇茬嚎孌電殑寮濮嬬偣涔板叆錛屽湪鏈楂樼偣鍗栧嚭銆傝屽湪涓嬮檷闃舵涓嶅嚭鎵嬨?br />


瀹炵幇浠g爜濡備笅錛?br />
public class Solution {
    public int maxProfit(int[] prices) {
        int len = prices.length;
        if(len<2){
            return 0;
        }
        
        int min=0;
        int result = 0;
        boolean inBuy = false;
        for(int i=0;i<len-1;++i){
            int p = prices[i];
            int q = prices[i+1];
            if(!inBuy){
                if(q>p){
                    inBuy = true;
                    min=p ;
                }
            }
            else{
                if(q<p){
                    result += (p-min);
                    inBuy = false;
                }
            }
        }
        if(inBuy){
            result += ((prices[len-1])-min);
        }
        return result;
    }
}


灝忔槑 2013-04-19 21:50 鍙戣〃璇勮
]]>鏈浣崇殑鑲$エ涔板崠鏃墮棿http://www.tkk7.com/sandy/archive/2013/04/19/398087.html灝忔槑灝忔槑Fri, 19 Apr 2013 07:03:00 GMThttp://www.tkk7.com/sandy/archive/2013/04/19/398087.htmlhttp://www.tkk7.com/sandy/comments/398087.htmlhttp://www.tkk7.com/sandy/archive/2013/04/19/398087.html#Feedback0http://www.tkk7.com/sandy/comments/commentRss/398087.htmlhttp://www.tkk7.com/sandy/services/trackbacks/398087.html
浣犲彧鑳借繘琛屼竴嬈′氦鏄擄紙涓嬈′拱榪涘拰涓嬈″崠鍑猴級錛岃璁′竴涓畻娉曟眰鍑烘渶澶х殑鏀剁泭銆?nbsp; 闃呰鍏ㄦ枃

灝忔槑 2013-04-19 15:03 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 亚洲av永久无码嘿嘿嘿 | baoyu777永久免费视频| 免费亚洲视频在线观看| 亚洲av成人无码网站…| 国产免费一区二区三区VR| 国产在亚洲线视频观看| 亚洲AV无码专区日韩| 日本一区二区在线免费观看| 免费大黄网站在线观| fc2成年免费共享视频网站| 亚洲中文字幕在线观看| 免费在线看黄网站| 亚洲国产美国国产综合一区二区| 国产精品免费一区二区三区四区| 亚洲欧洲免费视频| 国产卡一卡二卡三免费入口| 亚洲日本乱码卡2卡3卡新区| 国产精品深夜福利免费观看 | 亚洲精品tv久久久久久久久| 日本免费中文字幕| 亚洲乱人伦精品图片| 好大好深好猛好爽视频免费| 国产成人 亚洲欧洲| 亚洲精品自在在线观看| 亚洲w码欧洲s码免费| 亚洲av色香蕉一区二区三区蜜桃| 亚洲国产V高清在线观看| a级黄色毛片免费播放视频| 亚洲国产美女精品久久久久| 国产精品冒白浆免费视频| 男女一边桶一边摸一边脱视频免费 | 亚洲中文字幕久久精品无码VA| 免费一级肉体全黄毛片| av永久免费网站在线观看| 色偷偷亚洲女人天堂观看欧| 亚洲国产精品成人| 久久国产免费福利永久| 一级做a爰片久久免费| 亚洲麻豆精品果冻传媒| 亚洲精品国产精品乱码不卞| 亚洲无砖砖区免费|