耗子叔ARTS:第三周

3 篇文章 0 订阅

Algorithm:

 

/**

 * 804. Unique Morse Code Words

 * Easy

 * <p>

 * 404

 * <p>

 * 316

 * <p>

 * Favorite

 * <p>

 * Share

 * International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.

 * <p>

 * For convenience, the full table for the 26 letters of the English alphabet is given below:

 * <p>

 * [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]

 * Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, "cba" can be written as "-.-..--...", (which is the concatenation "-.-." + "-..." + ".-"). We'll call such a concatenation, the transformation of a word.

 * <p>

 * Return the number of different transformations among all words we have.

 * <p>

 * Example:

 * Input: words = ["gin", "zen", "gig", "msg"]

 * Output: 2

 * Explanation:

 * The transformation of each word is:

 * "gin" -> "--...-."

 * "zen" -> "--...-."

 * "gig" -> "--...--."

 * "msg" -> "--...--."

 * <p>

 * There are 2 different transformations, "--...-." and "--...--.".

 * Note:

 * <p>

 * The length of words will be at most 100.

 * Each words[i] will have length in range [1, 12].

 * words[i] will only consist of lowercase letters.

 */

 

JAVA:


public static int uniqueMorseRepresentations(String[] words) {

    String array[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};

    char[] arr = {};

    Map<Character, String> map = new HashMap<>();

    Set<String> set = new HashSet<>();

    int t = 97;

    StringBuilder sb = null;

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

        map.put((char) (t++), array[i]);

    }

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

        arr = words[i].toCharArray();

        sb = new StringBuilder();

        for (int j = 0; j < arr.length; j++) {

            sb.append(map.get(arr[j]));

        }

        set.add(sb.toString());

    }

    return set.size();

}
    return sb.toString();

}

 

 

GO:

func main() {

   var words []string = []string{"gin", "zen", "gig", "msg"}

   fmt.Println(uniqueMorseRepresentations(words))

}

func uniqueMorseRepresentations(words []string) int {

   slice := []string{".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."}

   temp := make(map[string]int)

   for i := 0; i < len(words); i++ {

      str := ""

      for _, v := range words[i] {

         str = str + slice[v-'a']

      }

      temp[str]++

   }

   return len(temp)



}

 

Review:

https://medium.com/the-code-review/top-10-docker-commands-you-cant-live-without-54fb6377f481

Top 10 Docker CLI commands you can’t live without

 

Docker 一般的常用命令

Docker is a great tool for building microservices, allowing you to create cloud-based applications and systems. To make the most of it via your terminal, here is a run down of the top 10 Docker commands for your terminal.

A container is launched by running an image. An image is an executable package that includes everything needed to run an application–the code, a runtime, libraries, environment variables, and configuration files.

container is a runtime instance of an image–what the image becomes in memory when executed (that is, an image with state, or a user process). You can see a list of your running containers with the command, docker ps, just as you would in Linux.from Docker Concepts

  1. docker ps — Lists running containers. Some useful flags include: -a / -all for all containers (default shows just running) and —-quiet /-q to list just their ids (useful for when you want to get all the containers).
  2. docker pull — Most of your images will be created on top of a base image from the Docker Hub registry. Docker Hub contains many pre-built images that you can pull and try without needing to define and configure your own. To download a particular image, or set of images (i.e., a repository), use docker pull.
  3. docker build — The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. Use the -t flag to label the image, for example docker build -t my_container . with the . at the end signalling to build using the currently directory.
  4. docker run — Run a docker container based on an image, you can follow this on with other commands, such as -it bash to then run bash from within the container. Also see Top 10 options for docker runa quick reference guide for the CLI command. docker run my_image -it bash
  5. docker logs — Use this command to display the logs of a container, you must specify a container and can use flags, such as --follow to follow the output in the logs of using the program. docker logs --follow my_container
  6. docker volume ls — This lists the volumes, which are the preferred mechanism for persisting data generated by and used by Docker containers.
  7. docker rm — Removes one or more containers. docker rm my_container
  8. docker rmi — Removes one or more images. docker rmi my_image
  9. docker stop — Stops one or more containers. docker stop my_containerstops one container, while docker stop $(docker ps -a -q) stops all running containers. A more direct way is to use docker kill my_container, which does not attempt to shut down the process gracefully first.
  10. Use them together, for example to clean up all your docker images and containers:
  • kill all running containers with docker kill $(docker ps -q)
  • delete all stopped containers with docker rm $(docker ps -a -q)
  • delete all images with docker rmi $(docker images -q)

To learn about deleting containers in more depth check out: Clean out your Docker images, containers and volumes with single commands

Find out more

There are lots more Docker commands, flags and combinations you can learn about in Docker’s CLI Documentation. Keep trying them out and they should become second nature.

This is just the start though, docker-compose is a tool to define multiple docker containers that work together in an application. To continue reading about docker-compose commands see my post: The ups and downs of docker-compose — how to run multi-container applications

Read more from ryanwhocodes

Docker quick reference guides

Docker in more depth

 

Tip:

新建实体类,对应表。内部有Date 类型。 手写data 写错,又因为,实体类使用lombok @data 注解,所以没看出来导包报错问题。

引起测试环境崩溃。

 

解决办法

重新引入包。以后注意认真编写代码

Share:

JAVA Lombok 的使用

https://mp.weixin.qq.com/s/XYkjdARYt5bN4X_ePiEb4w

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值