ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

LeetCode题解(八)0700-0799,Android攻防实战电子书

2021-12-14 15:05:53  阅读:152  来源: 互联网

标签:return String 题解 Java str 0799 Android submissions Example


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;
}
}

标签:return,String,题解,Java,str,0799,Android,submissions,Example
来源: https://blog.csdn.net/m0_65145426/article/details/121927443

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有