题目: 给定一个正整数,返回它在 Excel 表中相对应的列名称. 例如: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 29-> AC ... 52->AZ 需要的结果: 例如: 输入: 1 输出: "A" 输入: 28 输出: "AB" 输入: 701 输出: "ZY"整体思路:因为 题目 给的是 A = 1, 和 Excel 表格 A 是…
[题目] 给定一个字符串str,返回str中最长回文子串的长度 [举例] str="123", 1 str="abc1234321ab" 7 [暴力破解] 从左到右遍历字符串,遍历到每个字符的时候,以当前字符作为中心能够产生多大的回文字符串, 奇回文和偶 回文寻找方式不一样. 缺点:前面的寻找无法为后面的寻找提供任何帮助.没有记忆.加上记忆就好了. [Manacher] Manacher算法解决的问题是在线性时间内找到一个字符串的最长回文子串. 奇回文和偶回味在判断…
D. Black Hills golden jewels time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In Rapid City are located the main producers of the Black Hills gold jewelry, a very popular product among tour…
题目: 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,下标 ,a ,b , c 对应数相加等于 targe 找出所有满足条件且不重复的三元组下标 解析: 在一个list里面找出来三个数字使这三个数字相加等于目标targe, 这里是一个list 我们去循环这里面的元素,我们利用for循环, 第一个取来,然后后剩下的元素分别取循环上一个循环剩下的元素.这样保证了不重复,最后验证下,如果找出来的数字的值满足a+b+c=targe ,且三个数不相等,我们认为…
在leetCode看到一题目 Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target. Example 1: Input: 5 / \ 3 6 / \ \ 2 4 7 Target = 9 Output: True Example 2: Input: 5 /…
思想: 思想:用快慢指针先判断是否有环,有环则 假设头结点到环入口距离为n,环入口到快慢指针相遇结点距离为m,则慢指针走的路程 为m+n,而快指针走的路程为m+n+k*l (k*l表示绕环走的路程),我们知道快指针路程是慢指针 路程二倍,则k*l = m+n: 找到相遇结点后,让快指针指向头结点,然后让快慢指针都向后移动,当快指针向后移动n次时,就找到了环入口, 代码实现如下: public ListNode detectCycle(ListNode head) { if(head == nul…
例如, 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB ... 示例 1: 输入: 1 输出: "A" 示例 2: 输入: 28 输出: "AB" 示例 3: 输入: 701 输出: "ZY" public static String convertToTitle(int n) { StringBuilder sb = new StringBuilder()…
给定一个二叉树,返回其节点值的锯齿形层序遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如:给定二叉树 [3,9,20,null,null,15,7], 来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal著作权归领扣网络所有.商业转载请联系官方授权,非商业转载请注明出处. 答案: /** * Definition for a bi…
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as po…
Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left…