709. To Lower Case
[Description]
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
[Example]
Example 1:
Input: “Hello”
Output: “hello”
Example 2:
Input: “here”
Output: “here”
Example 3:
Input: “LOVELY”
Output: “lovely”
[Answer]
Runtime: 0 ms, faster than 100.00% of Java online submissions for To Lower Case.
Memory Usage: 34.1 MB, less than 99.91% of Java online submissions for To Lower Case.
class Solution {
public String toLowerCase(String str) {
return str.toLowerCase();
}
}
Runtime: 0 ms, faster than 100.00% of Java online submissions for To Lower Case.
Memory Usage: 34 MB, less than 99.91% of Java online submissions for To Lower Case.
class Solution {
public String toLowerCase(String str) {
char[] arrayChar = str.toCharArray();
for (int i = 0; i < arrayChar.length; i++) {
if (arrayChar[i] >= ‘A’ && arrayChar[i] <= ‘Z’)
arrayChar[i] += 32;
}
return new String(arrayChar);
}
}
class Solution {
public String toLowerCase(String str) {
StringBuilder sb = new StringBuilder();
for (char c : str.toCharArray()) {
if ((c - 0) >= 65 && (c - 0) <= 90) {
sb.append(Character.toChars(c + 32));
} else {
sb.append©;
}
}
return sb.toString();
}
}
728. Self Dividing Numbers
[Description]
A self-dividing number is a number that is divisible by every digit it contains.
For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.
Also, a self-dividing number is not allowed to contain the digit zero.
Given a lower and upper number bound, output a list of every possible self dividing number, including the bounds if pos
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
sible.
Example 1:
Input:
left = 1, right = 22
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
Note:
The boundaries of each input argument are 1 <= left <= right <= 10000.
[Answer]
Runtime: 7 ms, faster than 13.00% of Java online submissions for Self Dividing Numbers.
Memory Usage: 36.2 MB, less than 33.49% of Java online submissions for Self Dividing Numbers.
class Solution {
public List selfDividingNumbers(int left, int right) {
List list = new ArrayList();
while (left <= right) {
if (isSelfNumber(left))
list.add(left);
left++;
}
return list;
}
private boolean isSelfNumber(int num) {
if (num < 1)
return false;
if (num < 10)
return true;
String str = num + “”;
if (str.contains(“0”))
return false;
for (char c : str.toCharArray()) {
int n = Integer.parseInt("" + c);
if (num % n != 0)
return false;
}
return true;
}
}
771. Jewels and Stones
[Description]
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 stones you have are also jewels.
The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so “a” is considered a different type of stone from “A”.
[Example]
Example 1:
Input: J = “aA”, S = “aAAbbbb”
Output: 3
Example 2:
Input: J = “z”, S = “ZZ”
Output: 0
Note:
S and J will consist of letters and have length at most 50.
The characters in J are distinct.
[Answer]
Runtime: 1 ms, faster than 97.52% of Java online submissions for Jewels and Stones.
Memory Usage: 33.9 MB, less than 100.00% of Java online submissions for Jewels and Stones.
class Solution {
public int numJewelsInStones(String J, String S) {
int num = 0;
for(int i = 0; i < S.length(); i++) {
if(J.indexOf(S.substring(i, i + 1)) >= 0) num++;
}
return num;
}
}