原创 迷宮bfs應用(華爲OJ題目)

  'S'是開始位置,'#'表示牆,'.'是通路,'E'是終點,求最短路徑長度 #include <iostream> #include<vector> #include<string> #include<utility> #inclu

原创 洪水問題(bfs應用)

題目描述 在一個nxm矩陣形狀的城市裏爆發了洪水,洪水從(0,0)的格子流到這個城市,在這個矩陣中有的格子有一些建築,洪水只能在沒有建築的格子流動。請返回洪水流到(n - 1,m - 1)的最早時間(洪水只能從一個格子流到其相鄰的格子且洪

原创 rotate-list(循環移動鏈表)

題目描述 Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given1->2->3->4->5->

原创 LeetCode---unique-paths-ii(路徑個數)

題目描述 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can onl

原创 LeetCode--subsets(數組的所有可能子集合)

題目描述 Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descen

原创 LeetCode--set-matrix-zeroes(很巧妙的解法)

題目描述 Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow

原创 minimum-window-substring(最小區間子串)

題目描述 Given a string S and a string T, find the minimum window in S which will contain all the characters in T in comple

原创 LeetCode-maximal-rectangle(最大矩陣面積)

題目描述 Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the a

原创 partition-list(鏈表根據值分割兩部分)

題目描述 Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or

原创 interleaving-string(交叉字符串)

題目描述 Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given:s1 ="aabcc",s2 ="

原创 LeetCode--combinations(求一個數組指定個數所有組合)

題目描述 Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 an

原创 LeetCode--subsets-ii(所有可能的子集合)

題目描述 Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: Elements in a

原创 計算從1到n包含1的個數

薯隊長在平時工作中需要經常跟數字打交道,某一天薯隊長收到了一個滿是數字的表格,薯隊長注意到這些數字裏邊很多數字都包含1,比如101裏邊包含兩個1,616裏包含一個1。 請你設計一個程序幫薯隊長計算任意一個正整數n(0<n<=2147483

原创 兩個字符串的最長公共子串

問題:有兩個字符串str和str2,求出兩個字符串中最長公共子串長度。 比如:str=acbcbcef,str2=abcbced,則str和str2的最長公共子串爲bcbce,最長公共子串長度爲5。 算法思路: 1、把兩個字符串分別以行和

原创 單鏈錶轉換爲平衡搜索樹

題目描述 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. /**