java
文章平均质量分 58
帘外雨
学生一枚
展开
-
java之反射机制(reflection)
什么是反射?在Java中的反射机制是指在运行状态中,动态的获取任意一个类所有的属性和方法(包括方法签名和方法返回值等信息),并且任意一个对象都能够调用其任意一个方法。这种动态获取信息以及动态调用对象方法的功能成为Java语言的反射机制。反射机制在什么情况中使用?1、由于java多态的存在,使得对象运行时的类型和声明的类型不同,然而有些程序需要根据运行时的对象具体类型做出不同的处理,这时就需要用到反射原创 2017-03-14 16:34:20 · 415 阅读 · 0 评论 -
LeetCode:526. Beautiful Arrangement
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 <= i <原创 2017-09-07 20:43:15 · 279 阅读 · 0 评论 -
LeetCode: 498. Diagonal Traverse
Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. Example:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Outp原创 2017-09-15 20:27:33 · 285 阅读 · 0 评论 -
LeetCode:539. Minimum Time Difference
Given a list of 24-hour clock time points in “Hour:Minutes” format, find the minimum minutes difference between any two time points in the list. Example 1:Input: ["23:59","00:00"]Output: 1Note:The nu原创 2017-09-15 21:01:06 · 315 阅读 · 0 评论 -
Java基础:Java 强制类型转换
Java类型转换包括基本数据类型的类型转换以及对象类型转换。 1、基本数据类型转换 java基本数据类型包括:boolean、char、byte、short、int、float、double。其中只有boolean类型无法与其他类型进行转换,其他的数据类型之间可以相互转换。对于byte、short、int、float、double从后向前需要强制类型转换,从前向后可以自动转换。c原创 2017-09-09 10:54:02 · 338 阅读 · 0 评论 -
LeetCode: 22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "(原创 2017-09-17 21:44:25 · 240 阅读 · 0 评论 -
LeetCode:445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it原创 2017-09-15 19:46:29 · 199 阅读 · 0 评论 -
LeetCode: 672. Bulb Switcher II
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of st转载 2017-09-17 22:25:53 · 291 阅读 · 0 评论 -
LeetCode:260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1原创 2017-09-09 17:31:21 · 209 阅读 · 0 评论 -
去哪儿2017编程题
问题:对于每个测试实例,要求输出大于n的下一个对称数字。 分析:最小的对称数字必然是改变靠近对称轴的数字,因此对于输入的数字可以分成以下2种: 1)对称轴左边的数字大于对应位置的右边数字,此时直接将对称轴左边的数字对称到右边即可: 3840 -> 3883; 342 -> 343; 2)对称轴左边的数字小于或者等于对应位置的右边数字,此时,最小的对称数字必然是将对称轴左边的第原创 2017-09-26 15:03:52 · 409 阅读 · 0 评论 -
网易2018年编程题
魔法王国一共有n个城市,编号为0~n-1号,n个城市之间的道路连接起来恰好构成一棵树。 小易现在在0号城市,每次行动小易会从当前所在的城市走到与其相邻的一个城市,小易最多能行动L次。 如果小易到达过某个城市就视为小易游历过这个城市了,小易现在要制定好的旅游计划使他能游历最多的城市,请你帮他计算一下他最多能游历过多少个城市(注意0号城市已经游历了,游历过的城市不重复计算)。输入描述:输入包括两行,第原创 2017-09-10 11:42:07 · 4145 阅读 · 0 评论 -
网易2018校招编程题
一个合法的括号匹配序列被定义为: 1. 空串”“是合法的括号序列 2. 如果”X”和”Y”是合法的序列,那么”XY”也是一个合法的括号序列 3. 如果”X”是一个合法的序列,那么”(X)”也是一个合法的括号序列 4. 每个合法的括号序列都可以由上面的规则生成 例如”“, “()”, “()()()”, “(()())”, “(((()))”都是合法的。 从一个字符串S中移除零个或者多个字符得到的序列原创 2017-09-10 13:08:28 · 2273 阅读 · 0 评论 -
LeetCode 667. Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3, … , an],原创 2017-09-01 20:54:23 · 714 阅读 · 0 评论 -
665. Non-decreasing Array
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i原创 2017-09-01 21:59:01 · 471 阅读 · 0 评论 -
LeetCode:553. Optimal Division
Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at any position to change the原创 2017-09-07 20:06:27 · 337 阅读 · 0 评论 -
LeetCode:647. Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of原创 2017-09-07 19:12:04 · 209 阅读 · 0 评论 -
Leetcode:621. Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be原创 2017-09-04 21:23:03 · 203 阅读 · 0 评论 -
Leetcode:611. Valid Triangle Number
Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.Example 1:In原创 2017-09-04 21:38:09 · 205 阅读 · 0 评论 -
LeetCode: 581. Shortest Unsorted Continuous Subarray
Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need to find t原创 2017-09-05 14:21:22 · 168 阅读 · 0 评论 -
LeetCode:529. Minesweeper
Let’s play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representing the game board. ‘M’ represents an unrevealed mine, ‘E’ represents an unrevealed empty square, ‘B’ r原创 2017-09-13 09:35:25 · 212 阅读 · 0 评论 -
LeetCode: Add to List 414. Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1:Input: [3, 2, 1]Outpu原创 2017-09-06 17:23:14 · 183 阅读 · 0 评论 -
LeetCode:204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.Credits:Special thanks to @mithmatt for adding this problem and creating all test cases. 题意:输出小于n的素数(质数)的数目。(《编程之转载 2017-09-06 18:41:20 · 162 阅读 · 0 评论 -
LeetCode 382. Linked List Random Node
题目描述:LeetCode 382. Linked List Random NodeGiven a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen.Follow up:What if the转载 2017-09-14 20:07:37 · 230 阅读 · 0 评论 -
LeetCode: 479. Largest Palindrome Product
Find the largest palindrome made from the product of two n-digit numbers. Since the result could be very large, you should return the largest palindrome mod 1337.Example:Input: 2Output: 987Explanat原创 2017-09-06 21:49:47 · 1245 阅读 · 0 评论 -
LeetCode:384. Shuffle an Array
Discuss Pick One <!-- @END Action Button--> <div class="question-description"> <p></p><p>Shuffle a set of numbers without dup原创 2017-09-14 21:25:01 · 334 阅读 · 0 评论 -
LeetCode:419. Battleships in a Board
Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:You receive a valid board,原创 2017-09-07 15:31:18 · 182 阅读 · 0 评论 -
LeetCode:442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra space原创 2017-09-07 16:06:20 · 188 阅读 · 0 评论 -
LeetCode: 421. Maximum XOR of Two Numbers in an Array
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ i, j < n.Could you do this in O(n) runtime?Example:Input: [3, 10, 5, 25, 2,原创 2017-09-15 15:13:21 · 244 阅读 · 0 评论 -
LeetCode:406. Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this p原创 2017-09-07 18:22:33 · 209 阅读 · 0 评论 -
LeetCode:462. Minimum Moves to Equal Array Elements II
Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by 1原创 2017-09-11 10:49:50 · 200 阅读 · 0 评论