arts week04

arts

Posted by Woncz on August 16, 2019

Algorithm

LeetCode算法题

Given a string, find the length of the longest substring without repeating characters.

Example 1:

Input: “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. Example 2:

Input: “bbbbb” Output: 1 Explanation: The answer is “b”, with the length of 1. Example 3:

Input: “pwwkew” Output: 3 Explanation: The answer is “wke”, with the length of 3. Note that the answer must be a substring, “pwke” is a subsequence and not a substring.

Java 程序实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }

        int max = 1;
        Map<Character, Integer> prefix = new HashMap<>(s.length());
        for (int i = 0, repeatIndex = 0; i < s.length(); i++) {
            Character current = s.charAt(i);
            if (prefix.containsKey(current)) {
                repeatIndex = Math.max(prefix.get(current), repeatIndex);
            }
            max = Math.max(max, i - repeatIndex + 1);
            prefix.put(current, i + 1);
        }

        return max;
    }
}

Review

What Makes A Great Software Engineer?

通过调查微软公司多个部门,试图找出优秀软件工程师之所以优秀的原因:

  • Improving 与时俱进,不断学习

  • Passionate 有激情

  • Open-minded 求知若饥,虚心若愚

  • Data-driven 用数据事实说话

Tip

学习新知识,一是需要灵性,能够提纲挈领,执牛耳,有方式方法;二是需要韧劲,三分钟热度不可取,坚持不懈百折不挠才可以。

Share

2019年中总结