public class Test { public static void main(String[] args) { int[] a = {1, 2, 4, 6}; int[] b = a; int[] c = {1, 2, 4, 6}; //下面这个方法打印的是a数组的引用地址 System.out.println(a.toString()); //下面这个方法比较的是两个数组的引用是否相等 System.out.println("a.equals(b):"+a.equals(b…
这是悦乐书的第226次更新,第239篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第93题(顺位题号是434).计算字符串中的段数,其中段定义为非空格字符的连续序列.请注意,该字符串不包含任何不可打印的字符.例如: 输入:"Hello, my name is John" 输出:5 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使用Java语言编写和测试. 02 第一种解法 使用正则表达式,将其拆分成字符串数组…
这是悦乐书的第205次更新,第217篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第73题(顺位题号是344).编写一个以字符串作为输入并返回字符串的函数.例如: 输入:"hello" 输出:"olleh" 输入:"A man, a plan, a canal: Panama" 输出:"amanaP: lanac a, nalp a, nam A" 本次解题使用的开发工具是eclipse,jdk使…
题目:reverse words in a string Given an input string, reverse the string word by word. For example,Given s = "the sky is blue",return "blue is sky the". 解析:将字符串中的单词逆序输出 借助一个堆栈,从前向后遍历字符串,遇到空,跳过,直到非空字符,拼接word,等再次遇到空时,得到一个word,加入堆栈, 以此类推,直到…
题目: Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". click to show clarification. Clarification: What constitutes a word? A sequence of non-space characters con…
这个是Java的经典问题.许多类似的问题在stackoverflow被提问,有很多不正确或不完备的答案.如果不想太多你会认为这个问题比较简单.( The question is simple if you don't think too much.)如果你想的多的话,它会非常让你困扰. 1. 下面的代码片段是有有趣和让人困惑的 public static void main(String[] args) { String x = new String("ab"); change(x);…
题目: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", return false. 题解: 这道题还是像…
题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr eat / \ / \ g r e at / \ a t To scramble the string, we ma…