Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARTS 第十一周(2019.11.25-2019.12.01) #11

Open
caimel opened this issue Dec 11, 2019 · 0 comments
Open

ARTS 第十一周(2019.11.25-2019.12.01) #11

caimel opened this issue Dec 11, 2019 · 0 comments

Comments

@caimel
Copy link
Owner

caimel commented Dec 11, 2019

Algorithm 无重复字符的最长子串

  • 题目: 无重复字符的最长子串
  • 思路:
    使用map来记录当前最长子串的每个字符的位置,left记录当前最长子串的起始位置,遍历数组,当遇到重复字符时(map[v] >=left),重复说明map[v]有值不等于undefined,该表达式成立,则更新该字符的位置和起始位置往后移一位。直到数组遍历一遍。
/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function(s) {
    const map = {};
    let left = 0;
    
    return s.split('').reduce((max, v, i) => {
        left = map[v] >= left ? map[v] + 1 : left;
        map[v] = i;
        return Math.max(max, i - left + 1);
    }, 0);
    
};
  • 结果:987 / 987 个通过测试用例
    执行用时:120 ms

Review React的immutable:改变对象没有错

https://blog.logrocket.com/immutability-in-react-ebe55253a1cc/

Tip React Native 开发实用技巧

https://www.jianshu.com/p/ccba80f34f33

Share React Native 圆形进度条组件

https://www.npmjs.com/package/react-native-circular-progress

  • 实践
import React, { Component } from 'react'
import { AnimatedCircularProgress } from 'react-native-circular-progress'
import { Platform, StyleSheet, Text, View } from 'react-native'
import { scaleFontSize, scaleSize, scaleLandScapeSize } from '../../utils/screen'
import proptypes from 'prop-types'

const styles = StyleSheet.create({
    scoreContainer: {
        alignItems: 'center',
        paddingVertical: scaleSize(5),
        paddingHorizontal: scaleSize(20)
    },
    scoreText: { marginTop: scaleSize(5), fontSize: scaleFontSize(8) }
})

export default class ScoreCircle extends React.Component {
    static proptypes = {
        score: proptypes.number,
        color: proptypes.string,
        category: proptypes.string
    }
    constructor(props) {
        super(props);
        this.state = {
        }
    }
    render() {
        return (
            <View style={[styles.scoreContainer, this.props.scoreStyle]} >
                <AnimatedCircularProgress
                    size={scaleSize(80)}
                    width={scaleSize(6)}
                    lineCap='round'
                    fill={this.props.score}
                    tintColor={this.props.color}
                    backgroundColor='rgba(150,150,150,.2)' >{
                        (fill) => (
                            <Text>
                                {this.props.score + _('分')}
                            </Text>
                        )
                    }
                </AnimatedCircularProgress>
                <Text style={styles.scoreText}>
                    {this.props.category}
                </Text>
            </View>
        );
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant