三天两题
雨临Lewis
个人博客地址:https://lewky.cn
展开
-
不占用任何额外空间的情况下交换两个数的值
题目假如有x、y两个数,如何在不占用任何额外空间的情况下交换两个数的值?思路平时我们在交换两个数的值时,往往会用一个中间数temp来实现效果,现在需要不占用任何额外空间,自然就不能使用这种寻常的方法了;这里可以有两种方法来实现。方法一int x = 5;int y = 10;x = x + y;y = x - y;x = x - y;先将两个数之和附给x,接着x-y自然就是原...原创 2018-12-22 23:04:27 · 3424 阅读 · 0 评论 -
Java - 一道关于Arrays.asList的题目
Arrays.asList用来将数组转化为ArrayList,对于这个API有一些我们需要了解的知识点。传入参数为基础数据类型的数组public class Test { public static void main(final String[] args) { final int[] test = new int[]{1,2,3,4}; final...原创 2019-05-01 22:38:58 · 316 阅读 · 0 评论 -
Java - 一道关于整型和字符类型相加的题目
题目public class Test { public static void main(final String[] args) { final int a = 10; final int b = 20; System.out.println(a + '+' + b + '=' + (a + b)); }}乍一看,可能有...原创 2019-05-11 01:01:16 · 1826 阅读 · 0 评论 -
LeetCode - 136. Single Number
题目Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u...原创 2019-06-08 14:59:21 · 247 阅读 · 0 评论 -
LeetCode - 709. To Lower Case
题目Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.Example 1:Input: "Hello"Output: "hello"Example 2:Input: "here"Output: "here"Examp...原创 2019-06-08 15:00:08 · 237 阅读 · 0 评论 -
LeetCode - 344. Reverse String
题目Write a function that reverses a string. The input string is given as an array of characters char[].Do not allocate extra space for another array, you must do this by modifying the input array in-...原创 2019-06-08 15:01:17 · 271 阅读 · 0 评论 -
LeetCode - 771. Jewels and Stones
题目You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the ...原创 2019-06-08 15:01:59 · 328 阅读 · 0 评论 -
LeetCode - 412. Fizz Buzz
题目Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. ...原创 2019-06-08 15:02:40 · 493 阅读 · 0 评论