ARTS挑战-第四周

2019-04-14  本文已影响0人  陈_振

Algorithm

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.

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int charset[256] = {0};
        int left = 0, right = -1;
        int length = 0;
       
        while(left < s.size()){
            if(right+1 < s.size() && charset[s[right+1]] == 0){
                right++;
                charset[s[right]]++;
            } else {   
                charset[s[left]]--;
                left++;
            }
            length = max(length, right-left+1);
        }
        return length;
    }
};

Review

LLVM能做什么

Clang provides infrastructure to write tools that need syntactic and semantic information about a program. This document will give a short introduction of the different ways to write clang tools, and their pros and cons.
Clang提供了需要程序语法语义信息的编写工具的基础设施。本文将会简述编写clang工具的基本方法。

LibClang is a stable high level C interface to clang. When in doubt LibClang is probably the interface you want to use. Consider the other interfaces only when you have a good reason not to use LibClang.

LibClang是Clang的一个稳定的高级C接口。当你对是否使用LibClang有疑虑时,只有当您有充分的理由不使用LibClang时,再考虑其他接口。

Canonical examples of when to use LibClang:

使用LibClang的典型案例:

Use LibClang when you…:

使用LibClang当你:

Do not use LibClang when you…:

不要使用LibClang当你:

Clang Plugins allow you to run additional actions on the AST as part of a compilation. Plugins are dynamic libraries that are loaded at runtime by the compiler, and they’re easy to integrate into your build environment.
Clang插件允许你作为编译的一部分运行其他的操作。插件是被编译器在运行时动态加载的动态库,它们很容易集成到构建环境。

Canonical examples of when to use Clang Plugins:

使用Clang插件的典型案例:

Use Clang Plugins when you…:

使用Clang 插件当你:

Do not use Clang Plugins when you…:

不要使用Clang插件当你:

LibTooling is a C++ interface aimed at writing standalone tools, as well as integrating into services that run clang tools. Canonical examples of when to use LibTooling:

LibTooling是一个C++接口,旨在编写独立的工具,并集成到运行clang工具的服务中去。使用LibTooling的典型案例:

Use LibTooling when you…:

使用LibTooling当你:

Do not use LibTooling when you…:

不要使用LibTooling当你:

重点词汇

infrastructure ['ɪnfrə'strʌktʃɚ]
n. 基础设施
例句:Clang provides infrastructure to write tools .
canonical [kə'nɑnɪkl]
adj. 依教规的;权威的;
例句:Canonical examples of when to use LibClang.

** artifact** ['ɑrtə,fækt]
n. 人工制品;手工艺品;工件
例句:creating additional build artifacts from a single compile step.

** standalone** ['stændə,lon]
adj. 单独的
例句:writing standalone tools.

Tips

设计原则相关:

  1. 找出应用中可能需要变化之处,把它们独立出来,不要和那些不需要变化的代码混在一起。
  2. 针对接口编程,而不是针对实现编程。

Share

tokens.png
  1. 语法分析。
上一篇下一篇

猜你喜欢

热点阅读