![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
赢一把就睡
做一件事最好的时间是十年前,其次是现在
展开
-
leetcode 两两交换链表
1.题目 两两交换链表中相邻的元素 2.示例 输入:1->2->3->4 输出:2->1->4->3 3.代码 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } *原创 2021-01-19 22:54:09 · 151 阅读 · 0 评论 -
leetcode --- Search in Rotated Sorted Array
一.题目 在一个颠倒了一次的有序数组里查看是否指定数字的索引,如果有返回该数字在数组里的索引,没有返回-1 如: Input: nums = [4,5,6,7,0,1,2], target = 0 Output: 4 二.思路 既然是有序,肯定优先考虑二分查找,不过考虑到某些区域是顺序打乱的,需要对二分查找进行一点的调整即可 三.代码 class Solution { public int search(int[] nums, int targe...原创 2020-10-03 17:11:48 · 104 阅读 · 0 评论 -
leetcode ---next Permutation
一.题目 Implementnext permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The r...原创 2020-08-29 20:52:04 · 166 阅读 · 0 评论 -
leetcode---两数相除
1.题目描述 给定两个32位的除数和被除数,不使用除法求出商数 2.问题求解 除数设为n,被除数设为m,可以得到:m=n*(2^0+2^1+....2^t),由于被除数和除数都是32位,所以t<=32,时间复杂度为O(32)=O(1) 注意数字越界 3.代码实现 class Solution { public int divide(int ...原创 2020-03-12 09:09:17 · 195 阅读 · 0 评论 -
最长回文数
一.描述 给定一个字符串 s,找到 s 中最长的回文子串。 二.代码 public String longestPalindrome(String s) { if (s == null || s.length() == 0) { return ""; } int longest=s.length(); ...原创 2019-11-17 11:31:32 · 521 阅读 · 0 评论