LeetCode题解(九)0800-0899

g --.

h …

i …

j .—

k -.-

l .-…

m –

n -.

o —

p .–.

q --.-

r .-.

s …

t -

u …-

v …-

w .–

x -…-

y -.–

z --…

[Answer]

Runtime: 2 ms, faster than 80.74% of Java online submissions for Unique Morse Code Words.

Memory Usage: 35.4 MB, less than 98.71% of Java online submissions for Unique Morse Code Words.

class Solution {

public int uniqueMorseRepresentations(String[] words) {

if(words == null || words.length ==0)

return 0;

String[] morse = {“.-”,“-…”,“-.-.”,“-…”,“.”,“…-.”,“–.”,“…”,“…”,“.—”,“-.-”,“.-…”,“–”,“-.”,“—”,“.–.”,“–.-”,“.-.”,“…”,“-”,“…-”,“…-”,“.–”,“-…-”,“-.–”,“–…”};

HashSet set = new HashSet<>();

int count = 0;

for(int i = 0; i < words.length; i++) {

StringBuffer sb = new StringBuffer();

for(char c : words[i].toCharArray()) {

sb.append(morse[c - ‘a’]);

}

if (!set.contains(sb.toString())) {

count ++;

set.add(sb.toString());

}

}

return count;

}

}

class Solution {

public int uniqueMorseRepresentations(String[] words) {

if (words == null || words.length == 0)

return 0;

String[] code = { “.-”, “-…”, “-.-.”, “-…”, “.”, “…-.”, “–.”, “…”, “…”, “.—”, “-.-”, “.-…”, “–”,

“-.”, “—”, “.–.”, “–.-”, “.-.”, “…”, “-”, “…-”, “…-”, “.–”, “-…-”, “-.–”, “–…” };

HashSet set = new HashSet<>();

int count = 0;

for (int i = 0; i < words.length; i++) {

StringBuilder sb = new StringBuilder();

for (char c : words[i].toCharArray())

sb.append(code[c - ‘a’]);

if (!set.contains(sb.toString())) {

count++;

set.add(sb.toString());

}

}

return count;

}

}

832. Flipping an Image

[Description]

Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.

To flip an image horizontally means that each row of the image is reversed. For example, flipping [1, 1, 0] horizontally results in [0, 1, 1].

To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0. For example, inverting [0, 1, 1] results in [1, 0, 0].

Example 1:

Input: [[1,1,0],[1,0,1],[0,0,0]]

Output: [[1,0,0],[0,1,0],[1,1,1]]

Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].

Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]

Example 2:

Input: [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]

Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]

Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].

Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]

Notes:

1 <= A.length = A[0].length <= 20

0 <= A[i][j] <= 1

Answer:

Runtime: 0 ms, faster than 100.00% of Java online submissions for Flipping an Image.

Memory Usage: 36.6 MB, less than 99.91% of Java online submissions for Flipping an Image.

class Solution {

public int[][] flipAndInvertImage(int[][] A) {

int[][] B = new int[A.length][A[0].length];

for(int i = 0; i < A.length; i++) {

for(int j = 0; j < A[i].length; j++)

B[i][A[i].length - j - 1] = (A[i][j] == 0) ? 1 : 0;

}

return B;

}

}

class Solution {

public int[][] flipAndInvertImage(int[][] A) {

int[][] B = A; // FIXME: Only copy address of A to B

for(int i = 0; i < A.length; i++) {

for(int j = 0; j < A[i].length; j++)

B[i][A[i].length - j - 1] = (A[i][j] == 0) ? 1 : 0;

}

return B;

}

}

852. Peak Index in a Mountain Array

[Description]

Let’s call an array A a mountain if the following properties hold:

A.length >= 3

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

最后

由于题目很多整理答案的工作量太大,所以仅限于提供知识点,详细的很多问题和参考答案我都整理成了 PDF文件

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!

最后

由于题目很多整理答案的工作量太大,所以仅限于提供知识点,详细的很多问题和参考答案我都整理成了 PDF文件

[外链图片转存中…(img-yjT2FneL-1712289026712)]

[外链图片转存中…(img-gmlVUqeK-1712289026712)]

[外链图片转存中…(img-O4K4fFhs-1712289026713)]

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值