自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(10)
  • 收藏
  • 关注

原创 Leetcode 46. 全排列

给定一个 没有重复 数字的序列,返回其所有可能的全排列。示例:输入: [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...

2020-09-13 11:37:10 68 1

原创 NC105 二分查找

题目描述请实现有重复数字的有序数组的二分查找。输出在数组中第一个大于等于查找值的位置,如果数组中不存在这样的数,则输出数组长度加一。示例1输入复制5,4,[1,2,4,4,5]输出复制3题解:注意结束条件是left <= right,应为mid计算是下取整,如果用 left < right的话有可能无法访问到rightpackage com.wx.nowcoder;public class NC105 { public s..

2020-09-08 00:09:07 124

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

题目描述判断给定的链表中是否有环扩展:你能给出空间复杂度O(1)的解法么?题解:方法一:快慢指针法。慢指针一次走一步,快指针一次走两步,如果有环,快慢指针总会在某一点相遇。方法二:类似哈希法。遍历链表的每个节点,将其指针都指向head节点,如过存在环,则head一定会被再次访问package com.wx.nowcoder;public class NC4 { //方法一:快慢指针 public boolean hasCycle1(ListNode

2020-09-05 23:15:54 74

原创 NC88寻找第K大的数

题目描述有一个整数数组,请你根据快速排序的思路,找出数组中第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.

2020-09-05 22:24:07 150

原创 NC32求平方根

题目描述实现函数int sqrt(int x).计算并返回x的平方根示例1输入复制2输出复制1package 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 .

2020-09-05 18:27:40 183

原创 917. Reverse Only Letters

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..

2020-05-23 22:51:50 146

原创 443. String Compression

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

2020-05-13 23:07:08 118

原创 628. Maximum Product of Three Numbers

Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24Note:The length of the given array will be in range [3,104] and ..

2020-05-10 14:34:41 125

原创 605. Can Place Flowers

605. Can Place FlowersEasySuppose 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

2020-05-10 11:59:10 153

原创 Java设计模式之单例模式

单例模式单例模式(Singleton Pattern)是 Java 中最简单的设计模式之一。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。这种模式涉及到一个单一的类,该类负责创建自己的对象,同时确保只有单个对象被创建。这个类提供了一种访问其唯一的对象的方式,可以直接访问,不需要实例化该类的对象。单例模式的几种实现方式1.懒汉式package com.com...

2020-05-05 16:42:10 99 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除