原创 Spiral Matrix I && Spiral Matrix II
問題I描述 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For
原创 基站選址
問題描述 描述 需要在一個N × M的網格中建立一個通訊基站,通訊基站僅必須建立在格點上。 網格中有A個用戶,每個用戶的通訊代價是用戶到基站歐幾里得距離的平方。 網格中還有B個通訊公司,維護基站的代價是基站到最近的一個通訊公司的
原创 Unique Paths & Unique Paths II
思考: Unique Path 可以用動態規劃和排列組合解 Unique Path II 可以用動態規劃 想法 1、對與問題一,排列組合考慮,要走到重點總共有n+m-2步,其中m-1步down和n-1步right,如果在m
原创 Binary Tree Right Side View
思考:只需要知道每一行的最後一個節點值即可。 方法 1、考慮使用兩個隊列進行BFS,A隊列存放當前行的節點,B隊列存放當前節點的子節點,即當A隊列空時,最後一個訪問的節點即位當前行的最後一個節點。 2、遞歸遍歷。每一層都會有一個
原创 Rotate Image
問題描述 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). For exampl
原创 Rotate List
問題描述 Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3-
原创 Permutations II
問題描述 Given a collection of numbers that might contain duplicates, return all possible unique permutations. For exam
原创 Substring with Concatenation of All Words
問題描述 You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices
原创 House Robber II
問題描述 After robbing those houses on that street, the thief has found himself a new place for his thievery so that he wil
原创 Search for a Range
問題描述 Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s
原创 Implement strStr
問題描述 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part o
原创 Isomorphic Strings
問題描述 Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can
原创 Longest Valid Parentheses
問題描述 Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) pare
原创 2月29日
問題描述 描述 給定兩個日期,計算這兩個日期之間有多少個2月29日(包括起始日期)。 只有閏年有2月29日,滿足以下一個條件的年份爲閏年: 年份能被4整除但不能被100整除 年份能被400整除 輸入 第一行爲一個整數T,表示數據組
原创 Bitwise AND of Numbers Range
問題描述 Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusi