将一个给定字符串s根据给定的行数numRows,以从上往下、从左到右进行 Z 字形排列。 比如输入字符串为"PAYPALISHIRING"行数为 3 时,排列如下: Go P A H N A P L S I I G Y I R 之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"PAHNAPLSIIGYIR"。
zigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 1. 2. 3. 4. 5. return its zigzag level order traversal as: [...
这题的要点在于要求inplace,即不能生成一个新list然后把当前最小的加后面。所以要zig zag的缝起来,不过也不难。list的题在所有循环处把null pointer exception处理好就行了。 就是merge sort那个n-way merge,轮流出牌。这个题的重点是要用heap,这样每次新加一个元素的时侯能很快的找到新的min。还有,这是第一次...
题目要求出总和为 sum 的所有组合,组合需要去重。 这一题和第 47 题类似,只不过元素可以反复使用。 代码# Go packageleetcodeimport"sort"funccombinationSum(candidates[]int,targetint)[][]int{iflen(candidates)==0{return[][]int{}}c,res:=[]int{},[][]int{}sort.Ints(candidates)findcombinationSum...
binary tree level order traversal: BFS using queue. Can use queue.size instead of two queues. binary tree level order traversal II: BFS using queue. binary tree zig-zag level order traversal: BFS using stack. populating next right pointers in each node II and II: very special level order ...
[0006][Zig Zag Conversion] commit Jun 26, 2019 [0007][Reverse Integer] commit Jun 26, 2019 [0008][String To Integer (atoi)] commit Jun 26, 2019 [0009][Palindrome Number] commit Jun 26, 2019 [0010][Regular Expression Matching] commit Jun 24, 2019 [0011][Container With Most Water] co...
0006. Zig Zag Conversion 0007. Reverse Integer 0008. String to Integer Atoi 0009. Palindrome Number 0011. Container With Most Water 0012. Integer to Roman 0013. Roman to Integer 0014. Longest Common Prefix 0015.3 Sum 0016.3 Sum Closest 0017. Letter Combinations of a Phone Number 0018.4 Sum ...
33. Search in Rotated Sorted Array # 题目 # Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If found in the arr
[0006][Zig Zag Conversion] commit Jun 26, 2019 [0007][Reverse Integer] commit Jun 26, 2019 [0008][String To Integer (atoi)] commit Jun 26, 2019 [0009][Palindrome Number] commit Jun 26, 2019 [0010][Regular Expression Matching] commit Jun 24, 2019 [0011][Container With Most Water] co...
[0006][Zig Zag Conversion] [0007][Reverse Integer] [0008][String To Integer (atoi)] [0009][Palindrome Number] [0010][Regular Expression Matching] [0011][Container With Most Water] [0012][Integer To Roman] [0013][Roman To Integer] ...