This is a creation in Article, where the information may have evolved or changed. A preliminary look at the basic grammar of the go language, just to see the code quickly looked at the back to forget the front, so still want to combat, but just write a few topics feel a little waste of time, suddenly thought to do algorithm problems, so this time is to use go to achieve algorithm problems, on the one hand can deepen is using go grammar, On the one hand also improve their algorithm level, with stone.
----------------------------------------variable----------------------------------------
1) If a variable is not used, the Go compiler will report an error, rather than an alarm like Java. So if you are traversing an array using range, use _ instead of using the subscript value:
For _, R: = Range Result {
----------------------------------------Array----------------------------------------
1) Array initialization must specify the length of the array, the length of the array cannot be specified using variables, this is the same as C. In Java, you can use variables to specify the length of an array.
2) array as a parameter of the method can not write the length of the array, for example, func test (numbers []int)
3) When initializing an array, you can also not specify the length of the array
For example: [] int {1, 2}
----------------------------------------Map----------------------------------------
1) Use map without additional library
2) Map initialization, you can specify the size of the map, you can use the variable to specify the size of the map initialization
Buffer: = Make (Map[int]int, Len (numbers))
3) Getting the values in the map is simple: Mymap[key]
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.