1. /**
    2. * @param a: An integer
    3. * @param op: A character, +, -, *, /.
    4. * @param b: An integer
    5. * @return: The result
    6. */
    7. func Calculate(a int, op byte, b int) int {
    8. // write your code here
    9. res := 0
    10. switch op {
    11. case '+' :
    12. res = a + b
    13. case '-' :
    14. res = a - b
    15. case '*' :
    16. res = a * b
    17. case '/' :
    18. res = a / b
    19. }
    20. return res
    21. }
    1. /**
    2. * Definition for singly-linked list.
    3. * type ListNode struct {
    4. * Val int
    5. * Next *ListNode
    6. * }
    7. */
    8. /**
    9. * @param head: the head of linked list.
    10. * @return: An integer list
    11. */
    12. func ToArrayList(head *ListNode) []int {
    13. // write your code here
    14. slice := make([]int,0)
    15. for head != nil{
    16. slice = append(slice,head.Val)
    17. head = head.Next
    18. }
    19. return slice
    20. }
    1. /**
    2. * @param a: An integer array
    3. * @param index1: the first index
    4. * @param index2: the second index
    5. * @return: nothing
    6. */
    7. func SwapIntegers(a []int, index1 int, index2 int) {
    8. // write your code here
    9. a[index1],a[index2] = a[index2],a[index1]
    10. }
    1. /**
    2. * @param size: An integer
    3. * @return: An integer list
    4. */
    5. func Generate(size int) []int {
    6. // write your code here
    7. slice := make([]int, size)
    8. for i := 0; i < size; i++ {
    9. slice[i] = i + 1
    10. }
    11. return slice
    12. }