寬度優(yōu)先搜索

Java

Queue<TreeNode> queue = new LinkedList<>();
String[] vals = String.split(" ");
int result = Integer.parseInt(String);
Collections.reverse(List);
new int[]{1,0};
  1. BFS應(yīng)用場(chǎng)景
    圖的遍歷 Traversal in Graph
  • 層級(jí)遍歷 Level Order Traversal
  • 由點(diǎn)及面 Connected Component
  • 拓?fù)渑判?Topological Sorting

最短路徑 Shortest Path in Simple Graph

  • 僅限簡(jiǎn)單圖求最短路徑
  • 即规丽,圖中每條邊長(zhǎng)度都是1,或者邊長(zhǎng)都相等

非遞歸的方式找所有方案 Iteration solution for all possible results
? 這一點(diǎn)我們將在后面 DFS 的課上提到

  1. 復(fù)雜度
    二叉樹(shù) 時(shí)間O(V) 空間:同層節(jié)點(diǎn)個(gè)數(shù)最大值
    圖 時(shí)間O(V+E) 空間:最大深度
    優(yōu)化方案 雙向BFS Bidirectional BFS
  • 假設(shè)單向BFS需要搜索 N 層才能到達(dá)終點(diǎn)赌莺,每層的判斷量為 X,那么總的運(yùn)算量為 X ^ N 如果換成是雙向BFS艘狭,前后各自需要搜索 N / 2 層翠订,總運(yùn)算量為 2 * X ^ (N / 2)
  • 無(wú)向圖; 所有邊的長(zhǎng)度都為 1 或者長(zhǎng)度都一樣; 同時(shí)給出了起點(diǎn)和終點(diǎn)
  1. 二叉樹(shù)上的BFS
    102 Binary Tree Level Order Traversal
    297 Serialize and Deserialize Binary Tree
  • 訪問(wèn)到節(jié)點(diǎn)的時(shí)候 在結(jié)果字符串上添加當(dāng)前節(jié)點(diǎn)信息
  • serialize時(shí)候空節(jié)點(diǎn)也入隊(duì) 否則無(wú)法表示空節(jié)點(diǎn)
  1. 圖上的BFS
    注意節(jié)點(diǎn)不要重復(fù)入隊(duì)就好
    133 Clone Graph
    *127 Word Ladder
    *261 Graph Valid Tree
    lt431 Connected Component in Undirected Graph
  1. 矩陣上的BFS
    200 Number of Islands 四個(gè)
    lt611 Knight Shortest Path 八個(gè)
    *lt598 Zombie in Matrix
    lt573 Build Post Office II

  2. 拓?fù)渑判?br> 算法描述:
    統(tǒng)計(jì)每個(gè)點(diǎn)的入度
    將每個(gè)入度為 0 的點(diǎn)放入隊(duì)列(Queue)中作為起始節(jié)點(diǎn)
    不斷從隊(duì)列中拿出一個(gè)點(diǎn),去掉這個(gè)點(diǎn)的所有連邊(指向其他點(diǎn)的邊)官撼,其他點(diǎn)的相應(yīng)的入度 - 1
    一旦發(fā)現(xiàn)新的入度為 0 的點(diǎn)橙弱,丟回隊(duì)列中

求任意一個(gè)拓?fù)渑判?br> lt127 Topological Sorting
210 Course Schedule II
*269 Alien Dictionary 注意可能會(huì)有重復(fù)的字符對(duì) 這種情況下入度不更新
求是否存在拓?fù)渑判?br> 207 Course Schedule
求是否存在且僅存在一個(gè)拓?fù)湫?Queue中最多同時(shí)只有1個(gè)節(jié)點(diǎn)
*444 Sequence Reconstruction
注意 重復(fù)對(duì)不能重復(fù)統(tǒng)計(jì)入度
求所有的拓?fù)湫?DFS

102 Binary Tree Level Order Traversal

/**
 * Definition of TreeNode:
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left, right;
 *     public TreeNode(int val) {
 *         this.val = val;
 *         this.left = this.right = null;
 *     }
 * }
 */

public class Solution {
    /**
     * @param root: A Tree
     * @return: Level order a list of lists of integer
     */
    public List<List<Integer>> levelOrder(TreeNode root) {
        // write your code here
        List<List<Integer>> results = new ArrayList<>();
        if(root==null)
            return results;
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while(!queue.isEmpty()){
            int size = queue.size();
            List<Integer> list = new ArrayList<>();
            for(int i=0; i<size; i++){
                TreeNode node = queue.poll();
                if(node.left!=null)
                    queue.offer(node.left);
                if(node.right!=null)
                    queue.offer(node.right);
                list.add(node.val);
            }
            results.add(list);
        }
        return results;
    }
}

297 Serialize and Deserialize Binary Tree

/**
 * Definition of TreeNode:
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left, right;
 *     public TreeNode(int val) {
 *         this.val = val;
 *         this.left = this.right = null;
 *     }
 * }
 */


public class Solution {
    /**
     * This method will be invoked first, you should design your own algorithm 
     * to serialize a binary tree which denote by a root node to a string which
     * can be easily deserialized by your own "deserialize" method later.
     */
    public String serialize(TreeNode root) {
        // write your code here
        StringBuilder sb = new StringBuilder();
        if(root==null){
            return sb.toString();
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while(!queue.isEmpty()){
            TreeNode node = queue.poll();
            if(node==null){
                sb.append("# ");
                continue;
            }
            sb.append(node.val);
            sb.append(" ");
            queue.offer(node.left);
            queue.offer(node.right);
        }
        return sb.toString();
    }

    /**
     * This method will be invoked second, the argument data is what exactly
     * you serialized at method "serialize", that means the data is not given by
     * system, it's given by your own serialize method. So the format of data is
     * designed by yourself, and deserialize it here as you serialize it in 
     * "serialize" method.
     */
    public TreeNode deserialize(String data) {
        // write your code here
        if(data==null || data.length()==0)
            return null;
        String[] vals = data.split(" ");
        TreeNode root = new TreeNode(Integer.parseInt(vals[0]));
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        int index = 1;
        while(!queue.isEmpty()){
            TreeNode node = queue.poll();
            if(vals[index].equals("#")){
                node.left = null;
            }else{
                node.left = new TreeNode(Integer.parseInt(vals[index]));
                queue.offer(node.left);
            }
            index++;
            if(vals[index].equals("#")){
                node.right = null;
            }else{
                node.right = new TreeNode(Integer.parseInt(vals[index]));
                queue.offer(node.right);
            }
            index++;
        }
        return root;
    }
}

133 Clone Graph

/**
 * Definition for undirected graph.
 * class UndirectedGraphNode {
 *     int label;
 *     ArrayList<UndirectedGraphNode> neighbors;
 *     UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }
 * };
 */


public class Solution {
    /*
     * @param node: A undirected graph node
     * @return: A undirected graph node
     */
    public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
        // write your code here
        if(node==null)
            return null;
        UndirectedGraphNode newroot = new UndirectedGraphNode(node.label);
        Map<UndirectedGraphNode, UndirectedGraphNode> map = new HashMap<>();
        map.put(node, newroot);
        Queue<UndirectedGraphNode> queue = new LinkedList<>();
        queue.offer(node);
        while(!queue.isEmpty()){
            UndirectedGraphNode current = queue.poll();
            for(UndirectedGraphNode neighbor: current.neighbors){
                UndirectedGraphNode newNeighbor;
                if(!map.containsKey(neighbor)){
                    newNeighbor = new UndirectedGraphNode(neighbor.label);
                    map.put(neighbor, newNeighbor);
                    queue.offer(neighbor);
                }
                newNeighbor = map.get(neighbor);
                UndirectedGraphNode newCurrent = map.get(current);
                newCurrent.neighbors.add(newNeighbor);
            }
        }
        return newroot;
    }
}

127 Word Ladder

class Solution {
    public int ladderLength(String beginWord, String endWord, List<String> wordList) {
        Set<String> set = new HashSet<>();
        for(String str : wordList){
            set.add(str);
        }
        int result = 2;
        if(!set.contains(endWord))
            return 0;
        if(beginWord.equals(endWord))
            return 1;
        Queue<String> queue = new LinkedList<>();
        Set<String> visited = new HashSet<>();
        visited.add(beginWord);
        queue.offer(beginWord);
        while(!queue.isEmpty()){
            
            int size = queue.size();
            for(int i=0; i<size; i++){
                String current = queue.poll();
                for(String next : getNextWords(set, current, visited)){
                    if(endWord.equals(next))
                        return result;
                    queue.offer(next);
                }
            } 
           result++; 
        }
        return 0;
    }
    private List<String> getNextWords(Set<String> set, String str, Set<String> visited){
        List<String> result = new ArrayList<>();
        char[] chars = str.toCharArray();
        for(int i=0; i<chars.length; i++){
            for(char c='a'; c<'z'; c++){
                char charati = chars[i];
                if(c==chars[i])
                    continue;
                chars[i] = c;
                String temp = new String(chars);
                if(set.contains(temp) && !visited.contains(temp)){
                    result.add(temp);
                    visited.add(temp);
                }     
                chars[i] = charati;
            }
        }
        return result;
    }
}

261 Graph Valid Tree

class Solution {
    public boolean validTree(int n, int[][] edges) {
        return bfs(n, edges);
    }
    private boolean bfs(int n, int[][] edges){
        if(edges.length!=n-1)
            return false;
        Map<Integer, Set<Integer>> graph = new HashMap<>();
        for(int[] edge : edges){
            int n0 = edge[0];
            int n1 = edge[1];
            Set<Integer> set0 = graph.getOrDefault(n0, new HashSet<>());
            Set<Integer> set1 = graph.getOrDefault(n1, new HashSet<>());
            set0.add(n1);
            set1.add(n0);
            graph.put(n0, set0);
            graph.put(n1, set1);
        }
        Queue<Integer> queue = new LinkedList<>();
        Set<Integer> visited = new HashSet<>();
        queue.offer(0);
        visited.add(0);
        int count = 0;
        while(!queue.isEmpty()){
            int current = queue.poll();
            count++;
            for(Integer next : graph.getOrDefault(current, new HashSet<>())){
                if(visited.contains(next))
                    return false;
                visited.add(next);
                Set<Integer> set = graph.get(next);
                set.remove(current);
                graph.put(next, set);
                queue.offer(next);
            }
        }
        System.out.println(count);
        return count == n;
    }
}

lt431 Connected Component in Undirected Graph

/**
 * Definition for Undirected graph.
 * class UndirectedGraphNode {
 *     int label;
 *     ArrayList<UndirectedGraphNode> neighbors;
 *     UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }
 * };
 */


public class Solution {
    /*
     * @param nodes: a array of Undirected graph node
     * @return: a connected set of a Undirected graph
     */
    public List<List<Integer>> connectedSet(List<UndirectedGraphNode> nodes) {
        // write your code here
        if(nodes==null)
            return null;
        Set<UndirectedGraphNode> set = new HashSet<>();
        List<List<Integer>> result = new ArrayList<>();
        for(UndirectedGraphNode node: nodes){
            if(!set.contains(node)){
                set.add(node);
                List<Integer> temp = getBFS(nodes, node, set);
                result.add(temp);
            }
        }
        return result;
    }
    private List<Integer> getBFS(List<UndirectedGraphNode> nodes, UndirectedGraphNode node, Set<UndirectedGraphNode> set){
        List<Integer> result = new ArrayList<>();
        Queue<UndirectedGraphNode> queue = new LinkedList<>();
        queue.offer(node);
        while(!queue.isEmpty()){
            UndirectedGraphNode temp = queue.poll();
            result.add(temp.label);
            for(UndirectedGraphNode neighbor: temp.neighbors){
                if(!set.contains(neighbor)){
                    queue.offer(neighbor);
                    set.add(neighbor);
                }
            }
        }
        Collections.sort(result);
        return result;
    }
}

200 Number of Islands

class Solution {
    public int numIslands(char[][] grid) {
        if(grid==null || grid.length==0 || grid[0]==null || grid[0].length==0)
            return 0;
        int result = 0;
        boolean[][] visited = new boolean[grid.length][grid[0].length];
        for(int i=0; i<grid.length; i++){
            for(int j=0; j<grid[0].length; j++){
                if(grid[i][j]=='1'){
                    result++;
                    grid[i][j] = '0';
                    visited[i][j] = true;
                    bfs(grid, i, j, visited);
                }
            }
        }
        return result;
    }
    private void bfs(char[][] grid, int i, int j, boolean[][] visited){
        int[] dirx = {1, -1, 0, 0};
        int[] diry = {0, 0, 1, -1};
        Queue<int[]> queue = new LinkedList<>();
        queue.offer(new int[]{i, j});
        while(!queue.isEmpty()){
            int[] current = queue.poll();
            for(int k=0; k<4; k++){
                int x = current[0]+dirx[k];
                int y = current[1]+diry[k];
                if(isValid(visited, x, y, grid)){
                    queue.offer(new int[]{x, y});
                    grid[x][y] = '0';
                    visited[x][y] = true;
                }
            }
        }
    }
    private boolean isValid(boolean[][] visited, int x, int y, char[][] grid){
        return x>=0 && x<grid.length && y>=0 && y<grid[0].length && visited[x][y]==false && grid[x][y]=='1';
    }
}

lt611 Knight Shortest Path

/**
 * Definition for a point.
 * class Point {
 *     int x;
 *     int y;
 *     Point() { x = 0; y = 0; }
 *     Point(int a, int b) { x = a; y = b; }
 * }
 */

public class Solution {
    /**
     * @param grid: a chessboard included 0 (false) and 1 (true)
     * @param source: a point
     * @param destination: a point
     * @return: the shortest path 
     */
    public int shortestPath(boolean[][] grid, Point source, Point destination) {
        // write your code here
        if(grid==null || grid.length==0 || grid[0]==null || grid[0].length==0)
            return 0;
        if(source.x==destination.x && source.y==destination.y)
            return 0;
        Queue<int[]> queue = new LinkedList<>();
        queue.offer(new int[]{source.x, source.y});
        int[] dirx = {1, -1, 2, 2, 1, -1, -2, -2};
        int[] diry = {2, 2, 1, -1, -2, -2, 1, -1};
        boolean[][] visited = new boolean[grid.length][grid[0].length];
        visited[source.x][source.y] = true;
        int result = 0;
        while(!queue.isEmpty()){
            result++;
            int size = queue.size();
            System.out.println(size);
            for(int i=0; i<size; i++){
                int[] current = queue.poll();
                int x = current[0];
                int y = current[1];
                System.out.println(x+" "+y);
                for(int j=0; j<8; j++){
                    int newx = x+dirx[j];
                    int newy = y+diry[j];
                    if(isValid(newx, newy, grid, visited)){
                        if(newx==destination.x && newy==destination.y)
                            return result;
                        queue.offer(new int[]{newx, newy});
                        visited[newx][newy] = true;
                    }
                }
            }
        }
        return -1;
    }
    
    private boolean isValid(int x, int y, boolean[][] grid, boolean[][] visited){
        return x>=0 && x<grid.length && y>=0 && y<grid[0].length && grid[x][y]==false && visited[x][y]==false;
    }
}

598 Zombie in Matrix

public class Solution {
   /**
    * @param grid: a 2D integer grid
    * @return: an integer
    */
   public int zombie(int[][] grid) {
       // write your code here
       Queue<int[]> queue = new LinkedList<>();
       for(int i=0; i<grid.length; i++){
           for(int j=0; j<grid[0].length; j++){
               if(grid[i][j]==1)
                   queue.offer(new int[]{i,j});
           }
       }
       int days = 0;
       int[] dirx = {1, -1, 0, 0};
       int[] diry = {0, 0, 1, -1};
       while(!queue.isEmpty()){
           int size = queue.size();
           days++;
           for(int i=0; i<size; i++){
               int[] current = queue.poll();
               int x = current[0];
               int y = current[1];
               for(int k=0; k<4; k++){
                   int newx = x+dirx[k];
                   int newy = y+diry[k];
                   if(isValid(grid, newx, newy)){
                       grid[newx][newy] = 1;
                       queue.offer(new int[]{newx, newy});
                   }
               }
           }
       }
       for(int i=0; i<grid.length; i++){
           for(int j=0; j<grid[0].length; j++){
               if(grid[i][j]==0)
                   return -1;
           }
       }
       return days-1;
   }
   private boolean isValid(int[][] grid, int x, int y){
       return x>=0 && x<grid.length && y>=0 && y<grid[0].length && grid[x][y]==0;
   }
}

127 Topological Sorting

/**
 * Definition for Directed graph.
 * class DirectedGraphNode {
 *     int label;
 *     ArrayList<DirectedGraphNode> neighbors;
 *     DirectedGraphNode(int x) { label = x; neighbors = new ArrayList<DirectedGraphNode>(); }
 * };
 */

public class Solution {
    /*
     * @param graph: A list of Directed graph node
     * @return: Any topological order for the given graph.
     */
    public ArrayList<DirectedGraphNode> topSort(ArrayList<DirectedGraphNode> graph) {
        // write your code here
        Map<DirectedGraphNode, Integer> map = new HashMap<>();
        for(DirectedGraphNode node : graph){
            for(DirectedGraphNode neighbor : node.neighbors){
                map.put(neighbor, map.getOrDefault(neighbor, 0)+1);
            }
        }
        Queue<DirectedGraphNode> queue = new LinkedList<>();
        for(DirectedGraphNode node : graph){
            if(!map.containsKey(node)){
                queue.offer(node);
            }
        }
        ArrayList<DirectedGraphNode> result = new ArrayList<>();
        while(!queue.isEmpty()){
            DirectedGraphNode node = queue.poll();
            result.add(node);
            for(DirectedGraphNode neighbor : node.neighbors){
                map.put(neighbor, map.get(neighbor)-1);
                if(map.get(neighbor)==0)
                    queue.offer(neighbor);
            }
        }
        return result;
    }
}

210 Course Schedule II

class Solution {
    public int[] findOrder(int numCourses, int[][] prerequisites) {
        Map<Integer, Integer> map = new HashMap<>();
        Map<Integer, List<Integer>> graph = new HashMap<>();
        for(int[] prerequest : prerequisites){
            int in = prerequest[0];
            int out = prerequest[1];
            map.put(in, map.getOrDefault(in,0)+1);
            List<Integer> neighbors = graph.getOrDefault(out, new ArrayList<>());
            neighbors.add(in);
            graph.put(out, neighbors);
        }
        Queue<Integer> queue = new LinkedList<>();
        for(int i=0; i<numCourses; i++){
            if(!map.containsKey(i)){
                queue.offer(i);
            }
        }
        int count = 0;
        int[] result = new int[numCourses];
        while(!queue.isEmpty()){
            int out = queue.poll();
            result[count] = out;
            count++;
            for(Integer in : graph.getOrDefault(out, new ArrayList<>())){
                map.put(in, map.get(in)-1);
                if(map.get(in)==0)
                    queue.offer(in);
            }
        }
        if(count==numCourses)
            return result;
        return new int[0];
    }
}

269 Alien Dictionary

class Solution {
    public String alienOrder(String[] words) {
        Map<Character, Set<Character>> graph = new HashMap<>();
        Map<Character, Integer> indegree = new HashMap<>();
        Set<Character> alphabet = new HashSet<>();
        for(String word : words){
            for(int i=0; i<word.length(); i++){
                alphabet.add(word.charAt(i));
            }
        }
        for(int i=1; i<words.length; i++){
            String pre = words[i-1];
            String next = words[i];
            int j=0;
            while(j<pre.length() && j<next.length() ){
                if(pre.charAt(j)==next.charAt(j)){
                    j++;
                }else{
                    Set<Character> set = graph.getOrDefault(pre.charAt(j), new HashSet<>());
                    if(set.add(next.charAt(j))){
                        graph.put(pre.charAt(j), set);
                        indegree.put(next.charAt(j), indegree.getOrDefault(next.charAt(j), 0)+1);
                    }
                    break;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        Queue<Character> queue = new LinkedList<>();
        for(Character c : alphabet){
            if(!indegree.containsKey(c)){
                queue.offer(c);
            }
        }
        while(!queue.isEmpty()){
            Character c = queue.poll();
            sb.append(c);
            for(Character next : graph.getOrDefault(c, new HashSet<>())){
                indegree.put(next, indegree.get(next)-1);
                if(indegree.get(next)==0)
                    queue.offer(next);
            }
        }
        if(sb.length()==alphabet.size()){
            return sb.toString();
        }
        return "";
    }
}

207 Course Schedule

class Solution {
    public boolean canFinish(int numCourses, int[][] prerequisites) {
        Map<Integer, Integer> map = new HashMap<>();
        Map<Integer, List<Integer>> graph = new HashMap<>();
        for(int[] prerequest : prerequisites){
            int in = prerequest[0];
            int out = prerequest[1];
            map.put(in, map.getOrDefault(in,0)+1);
            List<Integer> neighbors = graph.getOrDefault(out, new ArrayList<>());
            neighbors.add(in);
            graph.put(out, neighbors);
        }
        Queue<Integer> queue = new LinkedList<>();
        for(int i=0; i<numCourses; i++){
            if(!map.containsKey(i)){
                queue.offer(i);
            }
        }
        int count = 0;
        while(!queue.isEmpty()){
            int out = queue.poll();
            count++;
            for(Integer in : graph.getOrDefault(out, new ArrayList<>())){
                map.put(in, map.get(in)-1);
                if(map.get(in)==0)
                    queue.offer(in);
            }
        }
        return count==numCourses;
    }
}

444 Sequence Reconstruction

class Solution {
    public boolean sequenceReconstruction(int[] org, List<List<Integer>> seqs) {
        // write your code here
        Map<Integer, Integer> indegree = new HashMap<>();
        Map<Integer, Set<Integer>> graph = new HashMap<>();
        
        int index = 0;
        for(List<Integer> seq : seqs){
            for(int i=1; i<seq.size(); i++){
                int in = seq.get(i);
                int out = seq.get(i-1);
                if(in>org.length || out>org.length)
                    return false;
                if(!graph.containsKey(in)){
                    graph.put(in, new HashSet<>());
                }
                Set<Integer> set = graph.getOrDefault(out, new HashSet<>());
                if(set.add(in)){
                    graph.put(out, set);
                    indegree.put(in, indegree.getOrDefault(in, 0)+1);
                }
                
            }
        }
        System.out.println(indegree.size());
        System.out.println(graph.size());
        Queue<Integer> queue = new LinkedList<>();
        if(indegree.containsKey(org[0]))
            return false;
        queue.offer(org[0]);
        while(!queue.isEmpty()){
            Integer current = queue.poll();
            if(org[index]!=current)
                return false;
            index++;
            for(Integer next : graph.getOrDefault(current, new HashSet<>())){
                indegree.put(next, indegree.get(next)-1);
                if(indegree.get(next)==0)
                    queue.offer(next);
            }
            if(queue.size()>1)
                return false;
        }
        return index==org.length;
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市在讶,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌构哺,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,273評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件残拐,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡溪食,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,349評(píng)論 3 398
  • 文/潘曉璐 我一進(jìn)店門(mén)错沃,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)袱衷,“玉大人,你說(shuō)我怎么就攤上這事致燥。” “怎么了嫌蚤?”我有些...
    開(kāi)封第一講書(shū)人閱讀 167,709評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)脱吱。 經(jīng)常有香客問(wèn)我,道長(zhǎng)箱蝠,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,520評(píng)論 1 296
  • 正文 為了忘掉前任牙瓢,我火速辦了婚禮,結(jié)果婚禮上矾克,老公的妹妹穿的比我還像新娘。我一直安慰自己胁附,他們只是感情好酒繁,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,515評(píng)論 6 397
  • 文/花漫 我一把揭開(kāi)白布州袒。 她就那樣靜靜地躺著,像睡著了一般稳析。 火紅的嫁衣襯著肌膚如雪喧伞。 梳的紋絲不亂的頭發(fā)上寝凌,一...
    開(kāi)封第一講書(shū)人閱讀 52,158評(píng)論 1 308
  • 那天照棋,我揣著相機(jī)與錄音茂蚓,去河邊找鬼禀挫。 笑死抬闯,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的溶握。 我是一名探鬼主播,決...
    沈念sama閱讀 40,755評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼睡榆,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼袍榆!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起包雀,我...
    開(kāi)封第一講書(shū)人閱讀 39,660評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎才写,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體赞草,經(jīng)...
    沈念sama閱讀 46,203評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,287評(píng)論 3 340
  • 正文 我和宋清朗相戀三年蜕劝,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了檀头。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片岖沛。...
    茶點(diǎn)故事閱讀 40,427評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡搭独,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出牙肝,到底是詐尸還是另有隱情,我是刑警寧澤配椭,帶...
    沈念sama閱讀 36,122評(píng)論 5 349
  • 正文 年R本政府宣布,位于F島的核電站股缸,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏敦姻。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,801評(píng)論 3 333
  • 文/蒙蒙 一镰惦、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧旺入,春花似錦、人聲如沸眨业。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,272評(píng)論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至聘殖,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間奸腺,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,393評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工突照, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,808評(píng)論 3 376
  • 正文 我出身青樓筑舅,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親翠拣。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,440評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容

  • 背景 一年多以前我在知乎上答了有關(guān)LeetCode的問(wèn)題, 分享了一些自己做題目的經(jīng)驗(yàn)误墓。 張土汪:刷leetcod...
    土汪閱讀 12,747評(píng)論 0 33
  • 二叉樹(shù)結(jié)構(gòu): 二叉樹(shù)寬度優(yōu)先搜索: 按照二叉樹(shù)的層數(shù)依次從左到右訪問(wèn)二叉樹(shù)的節(jié)點(diǎn)莺奔;例如:給定一個(gè)二叉樹(shù): 按照寬度...
    LdpcII閱讀 5,231評(píng)論 0 2
  • 寬度優(yōu)先搜索又稱(chēng)廣度優(yōu)先搜索,簡(jiǎn)稱(chēng)bfs弊仪。搜索的方式是:從一個(gè)點(diǎn)開(kāi)始,逐層的遍歷訪問(wèn)周?chē)狞c(diǎn)励饵。比如有一個(gè)5*5的矩...
    ShutLove閱讀 1,078評(píng)論 0 3
  • Validate Binary Search Tree Same Tree (基礎(chǔ)) 101.symmetric ...
    lifesmily閱讀 318評(píng)論 0 0
  • 眾所周知,昆蟲(chóng)記是一部名著役听。 法國(guó)的法布爾創(chuàng)造了這本驚天名著。該書(shū)講述了昆蟲(chóng)的種類(lèi)特征典予,習(xí)性和婚...
    優(yōu)秀的藍(lán)雞閱讀 573評(píng)論 2 3