<?xml version="1.0" encoding="utf-8" ?><rss version="2.0"><channel><title><![CDATA[ahcdwx的博客]]></title><description><![CDATA[]]></description><link>https://blog.youkuaiyun.com/ahcdwx</link><language>zh-cn</language><generator>https://blog.youkuaiyun.com/</generator><copyright><![CDATA[Copyright &copy; ahcdwx]]></copyright><item><title><![CDATA[Leetcode 46. 全排列]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/108560568</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/108560568</guid><author>ahcdwx</author><pubDate>Sun, 13 Sep 2020 11:37:10 +0800</pubDate><description><![CDATA[给定一个 没有重复 数字的序列，返回其所有可能的全排列。

示例:

输入: [1,2,3]
输出:
[
 [1,2,3],
 [1,3,2],
 [2,1,3],
 [2,3,1],
 [3,1,2],
 [3,2,1]
]

题解：

这道理比较简单的解法是开辟一个visit[]数组，记录曾访问过的节点。其实有更好的方法，完全可以避免，也就是说不开visit数组也完全可以。


package com.wx.leetcode.backtrack;

import java.util.Arra...]]></description><category></category></item><item><title><![CDATA[NC105 二分查找]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/108459254</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/108459254</guid><author>ahcdwx</author><pubDate>Tue, 08 Sep 2020 00:09:07 +0800</pubDate><description><![CDATA[题目描述

请实现有重复数字的有序数组的二分查找。

输出在数组中第一个大于等于查找值的位置，如果数组中不存在这样的数，则输出数组长度加一。

示例1

输入

复制


5,4,[1,2,4,4,5]

输出

复制


3

题解：

注意结束条件是left &lt;= right,应为mid计算是下取整，如果用 left &lt; right的话有可能无法访问到right




package com.wx.nowcoder;

public class NC105 {
    public s..]]></description><category></category></item><item><title><![CDATA[NC判断给定的链表中是否有环]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/108426003</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/108426003</guid><author>ahcdwx</author><pubDate>Sat, 05 Sep 2020 23:15:54 +0800</pubDate><description><![CDATA[题目描述

判断给定的链表中是否有环

扩展：

你能给出空间复杂度O（1）的解法么？

题解：

方法一：

快慢指针法。慢指针一次走一步，快指针一次走两步，如果有环，快慢指针总会在某一点相遇。

方法二：

类似哈希法。遍历链表的每个节点，将其指针都指向head节点，如过存在环，则head一定会被再次访问


package com.wx.nowcoder;

public class NC4 {
    //方法一：快慢指针
    public boolean hasCycle1(ListNode ]]></description><category></category></item><item><title><![CDATA[NC88寻找第K大的数]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/108425455</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/108425455</guid><author>ahcdwx</author><pubDate>Sat, 05 Sep 2020 22:24:07 +0800</pubDate><description><![CDATA[题目描述

有一个整数数组，请你根据快速排序的思路，找出数组中第K大的数。

给定一个整数数组a,同时给定它的大小n和要找的K(K在1到n之间)，请返回第K大的数，保证答案存在。

测试样例：


[1,3,5,2,2],5,3


返回：2

题解：

利用快速排序的方法，找准第一个数的最终位置，下标为index。如果它的右侧数量正好是k-1个，那么它就是第k大的数，因为比它大的数最终都会在它的右边；如果右侧比k-1小，则要找的数在左边，递归求解左边第k-（右侧个数+1）




package com.]]></description><category></category></item><item><title><![CDATA[NC32求平方根]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/108422968</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/108422968</guid><author>ahcdwx</author><pubDate>Sat, 05 Sep 2020 18:27:40 +0800</pubDate><description><![CDATA[题目描述

实现函数int sqrt(int x).

计算并返回x的平方根

示例1

输入

复制


2

输出

复制


1


package com.wx.classical_code;

public class NC32 {
    public int sqrt(int x) {
        if (x == 0) return 0;
        if (x == 1) return 1;
        int left = 1;
        int right = x .]]></description><category></category></item><item><title><![CDATA[917. Reverse Only Letters]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/106307715</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/106307715</guid><author>ahcdwx</author><pubDate>Sat, 23 May 2020 22:51:50 +0800</pubDate><description><![CDATA[Given a string S, return the "reversed" string where all characters that are not a letterstay in the same place, and all letters reverse their positions.



Example 1:


Input: "ab-cd"
Output: "dc-ba"


Example 2:


Input: "a-bC-dEf-ghIj"
Output: "j-Ih-g..]]></description><category></category></item><item><title><![CDATA[443. String Compression]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/106109063</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/106109063</guid><author>ahcdwx</author><pubDate>Wed, 13 May 2020 23:07:08 +0800</pubDate><description><![CDATA[Given an array of characters, compress it in-place.

The length after compression must always be smaller than or equal to the original array.

Every element of the array should be a character (not int) of length 1.

After you are done modifying the input a]]></description><category></category></item><item><title><![CDATA[628. Maximum Product of Three Numbers]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/106035855</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/106035855</guid><author>ahcdwx</author><pubDate>Sun, 10 May 2020 14:34:41 +0800</pubDate><description><![CDATA[Given an integer array, find three numbers whose product is maximum and output the maximum product.

Example 1:


Input: [1,2,3]
Output: 6




Example 2:


Input: [1,2,3,4]
Output: 24




Note:

The length of the given array will be in range [3,104] and ..]]></description><category></category></item><item><title><![CDATA[605. Can Place Flowers]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/106034225</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/106034225</guid><author>ahcdwx</author><pubDate>Sun, 10 May 2020 11:59:10 +0800</pubDate><description><![CDATA[605. Can Place Flowers

Easy

Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.

Given a flowerbed (represented]]></description><category></category></item><item><title><![CDATA[Java设计模式之单例模式]]></title><link>https://blog.youkuaiyun.com/ahcdwx/article/details/105933970</link><guid>https://blog.youkuaiyun.com/ahcdwx/article/details/105933970</guid><author>ahcdwx</author><pubDate>Tue, 05 May 2020 16:42:10 +0800</pubDate><description><![CDATA[单例模式

单例模式（Singleton Pattern）是 Java 中最简单的设计模式之一。这种类型的设计模式属于创建型模式，它提供了一种创建对象的最佳方式。

这种模式涉及到一个单一的类，该类负责创建自己的对象，同时确保只有单个对象被创建。这个类提供了一种访问其唯一的对象的方式，可以直接访问，不需要实例化该类的对象。

单例模式的几种实现方式

1.懒汉式


package com.com...]]></description><category></category></item></channel></rss>