1. /**
    2. * @param a: an array of float numbers
    3. * @return: a float number
    4. */
    5. func MaxOfArray(a []float32) float32 {
    6. // write your code here
    7. max := a[0]
    8. for i := 1; i < len(a); i++ {
    9. if a[i] > max {
    10. max = a[i]
    11. }
    12. }
    13. return max
    14. }
    1. public class School {
    2. /*
    3. * Declare a private attribute *name* of type string.
    4. */
    5. // write your code here
    6. private String name;
    7. /**
    8. * Declare a setter method `setName` which expect a parameter *name*.
    9. */
    10. // write your code here
    11. public void setName(String name) {
    12. this.name = name;
    13. }
    14. /**
    15. * Declare a getter method `getName` which expect no parameter and return
    16. * the name of this school
    17. */
    18. // write your code here
    19. public String getName() {
    20. return this.name;
    21. }
    22. }
    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. * @param val: An integer.
    11. * @return: a linked node or null.
    12. */
    13. func FindNode(head *ListNode, val int) *ListNode {
    14. // write your code here
    15. for head != nil {
    16. if head.Val == val{
    17. return head
    18. }
    19. head = head.Next
    20. }
    21. return nil
    22. }
    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: a middle node of the linked list
    11. */
    12. func MiddleNode(head *ListNode) *ListNode {
    13. // write your code here
    14. count := 0
    15. h := head
    16. for h != nil {
    17. count++
    18. h = h.Next
    19. }
    20. m := count / 2
    21. if count%2 == 0 {
    22. m--
    23. }
    24. for i := 0; i < m; i++ {
    25. head = head.Next
    26. }
    27. return head
    28. }
    1. func MiddleNode(head *ListNode) *ListNode {
    2. // write your code here
    3. if head == nil || head.Next == nil || head.Next.Next == nil {
    4. return head
    5. }
    6. pre := head
    7. cur := head.Next.Next
    8. for cur.Next != nil && cur.Next.Next != nil {
    9. pre = pre.Next
    10. cur = cur.Next.Next
    11. }
    12. return pre.Next
    13. }
    1. import "strconv"
    2. func StringToInteger(target string) int {
    3. // write your code here
    4. i, _ := strconv.Atoi(target)
    5. return i
    6. }