- 博客(17)
- 收藏
- 关注
原创 Vector 源码解析(jdk1.8)
Vector 是 Java 提供的可以自动增长的动态数组,同时是线程安全的。 Java的继承体系: 成员变量 // 存放元素的数组 protected Object[] elementData; // 元素个数 protected int elementCount; //容器自动增大值 protected int capacityIncrement; 构造函数 public Ve...
2019-11-29 10:24:16
153
原创 Java 对象克隆
对于8种基本类型和String类型来说,克隆一般为以下: int a = 10; int b = a; 而对于引用类型,就相对复杂一些 定义一个测试类CloneDemo: public class CloneDemo { int id; String name; public CloneDemo(int id, String name){ this.id = id; this.n...
2019-11-22 19:01:59
163
原创 打开转盘锁
问题描述 你有一个带有四个圆形拨轮的转盘锁。每个拨轮都有10个数字: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’ 。每个拨轮可以自由旋转:例如把 ‘9’ 变为 ‘0’,‘0’ 变为 ‘9’ 。每次旋转都只能旋转一个拨轮的一位数字。 锁的初始数字为 ‘0000’ ,一个代表四个拨轮的数字的字符串。 列表 deadends 包含了一组死亡数字,一...
2019-11-22 00:06:08
183
原创 二叉树相关的算法(一)
二叉树的定义 // java public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } 把字符串转为二叉树, 字符串形式[1,2,3] public static TreeNode stringToTreeNode(Str...
2019-11-17 23:10:12
160
原创 Decode Ways
问题描述 A message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given a non-empty string containing only digits, determine...
2019-11-16 22:30:39
84
原创 最长公共前缀
问题描述 Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. Example 1: Input: [“flower”,“flow”,“flight”] Outpu...
2019-11-15 23:23:45
123
原创 4Sum
问题描述 Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum o...
2019-11-14 22:23:51
93
原创 接雨水
问题描述 Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by a...
2019-11-13 22:51:08
81
原创 简化路径
问题描述 Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path. In a UNIX-style file system, a period . refers to the current directory. Furtherm...
2019-11-12 22:31:02
158
原创 字符串的排列
问题描述 给定两个字符串 s1 和 s2,写一个函数来判断 s2 是否包含 s1 的排列。 换句话说,第一个字符串的排列之一是第二个字符串的子串。 示例1: 输入: s1 = "ab" s2 = "eidbaooo" 输出: True 解释: s2 包含 s1 的排列之一 ("ba"). 示例2: 输入: s1= "ab" s2 = "eidboaoo" 输出: False 注意: 输入的字符...
2019-11-11 22:17:13
167
原创 反转链表
问题描述 反转一个单链表。比如,输入: 1->2->3->4->5->NULL,输出: 5->4->3->2->1->NULL。 如下是链表节点的定义: /** * Java 定义 * public class ListNode { * int val; * ListNode next; * ListNo...
2019-11-10 14:06:07
86
原创 寻找两个有序数组的中位数
问题描述 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。 你可以假设 nums1 和 nums2 不会同时为空。 示例 1: nums1 = [1, 3] nums2 = [2] 则中位数是 2.0 示例 2: nums1 = [1, 2] nums2 = [3, 4] 则中位数是...
2019-11-09 22:28:40
83
原创 两两交换链表中的节点
问题描述 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。 示例: 1->2->3->4, 你应该返回 2->1->4->3. 解题思路: 解决该问题可以通过两种方式: 一是交换相邻节点的值,二是改变next指针的方向。 代码 解法一 递归 交换相邻节点的值 public ListNo...
2019-11-08 22:05:46
90
原创 螺旋矩阵
问题描述 给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。 实例一: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] 输出: [1,2,3,6,9,8,7,4,5] 实例二: 输入: [ [1, 2, 3, 4], [5, 6, 7, 8], [9,10,11,12] ] 输出: [1,2,3...
2019-11-07 23:15:20
148
原创 对角线遍历
@ 题目描述 给定一个含有 M x N 个元素的矩阵(M 行,N 列),请以对角线遍历的顺序返回这个矩阵中的所有元素,对角线遍历如下图所示。 实例: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] 输出: [1,2,4,7,5,3,6,8,9] 说明: 给定矩阵中的元素总数不会超过 100000 。 解题思路 在遍历二维数组中主要有两个方向变换...
2019-11-06 23:46:09
402
原创 C# 实现简单的登录
环境:Visual Studio 2013 , Sql Server 2017项目分为三层:UI , Dao, Model UI 层:用于接受客户传递的信息,提交给Dao 层进行处理,显示返回处理的结果代码:Dao层:项目只涉及一个用户表,所以Dao就是对用户表的操作using System;using System.Collections.Generic;using System.Linq;u...
2018-05-31 16:21:54
3274
原创 C# CPoint作为基类,派生出描述一条直线的类Cline,定义一个函数求出两点间的距离。再派生出一个矩形类CRect。要求成员函数能求矩形的周长和面积等
using System;namespace day327{ public class CPoint { double x; double y; public CPoint(double x,double y) { this.x = x; this.y = y; } ...
2018-03-27 20:57:18
4074
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人