Skip to content

Latest commit

 

History

History
129 lines (101 loc) · 4.19 KB

File metadata and controls

129 lines (101 loc) · 4.19 KB

1.Algorithm - Vowels, Two Pointers

[345]  Reverse Vowels of a String

Easy    Two Pointers    String

Given a string s, reverse only all the vowels in the string and return it.

The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both cases.

Example 1:

Input: s = "hello"
Output: "holle"

Example 2:

Input: s = "leetcode"
Output: "leotcede"

解答

(1).常规解法, 双指针遍历,时间复杂度 O(n)

注意byte与string的互相转换

func reverseVowels(s string) string {
	if len(s) <= 1 {
		return s
	}

	b := []byte(s)
	begin, end := 0, len(b)-1
	for begin < end {
		if !isVowel(b[begin]) {
			begin++
			continue
		}

		if !isVowel(b[end]) {
			end--
			continue
		}
		b[begin], b[end] = b[end], b[begin]
		begin++
		end--
	}

	return string(b)
}

func isVowel(c byte) bool {
	if c < 'a' {
		c += 32
	}
	return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'
}
(2).方法类似1, 双指针遍历,构造map进行遍历比较,时间复杂度 O(n)

注意byte与string, byte与rune之间的互相转换

func reverseVowels(s string) string {
	if len(s) <= 1 {
		return s
	}

	vowels := "aeiouAEIOU"
	vowelMap := make(map[byte]bool)
	for _, val := range vowels {
		vowelMap[byte(val)] = true
	}

	b := []byte(s)
	begin, end := 0, len(s)-1
	for begin < end {
		if !vowelMap[b[begin]] {
			begin++
			continue
		}

		if !vowelMap[b[end]] {
			end--
			continue
		}

		b[begin], b[end] = b[end], b[begin]
		begin++
		end--
	}
	return string(b)
}

2.Review - It's Rust all the way down

Rust 是写前端基建,是当下趋势;Rust 语言在前端工具链的影响越来越大

3.Tip - byte and rune(golang)

3.1 byte and rune

  • Golang has integer types called byte and rune that are aliases for uint8 and int32 data types
  • The byte data type represents ASCII characters while the rune data type represents a more broader set of Unicode characters that are encoded in UTF-8 format.
  • The default type for character values is rune

3.2 deploy local jar to local maven repository

4.Share - D2C(Design To Code)

前端从最初的脚手架工具、组件库、持续集成体系、自动化测试、多端适配到现在的全面低代码平台、前端智能化、在线IDE,大前端一直朝着提高生产力,提高研发效能的方向演进。

在D2C解决方案上,目前有以下几种开源方案:CodeFun, imgcook,58 Picasso,具体对比可以参考以下几个附件。可能方案有更多,只是自己刚刚了解这块,待后续学习后补充。通过去这三种方案的相关官网了解,觉得阿里的imgcook在文档,使用教程方面都做的非常不错,特别是关联博客中的智能生成代码2020,2019系列文章,都非常不错,比较容易入门。