- 博客(30)
- 收藏
- 关注
原创 二叉树后序遍历
Given the root of a binary tree,use golang tofunc postorderTraversal(root *TreeNode) (res []int) { var postorder func(*TreeNode) postorder = func(node *TreeNode) { if node == nil { return } postorder(node.Left
2022-05-31 17:44:31
66
原创 二叉树最大深度
Given therootof a binary tree, use golang to returnits maximum depth.func maxDepth(root *TreeNode) int { if root == nil { return 0 } return max(maxDepth(root.Left), maxDepth(root.Right)) + 1}func max(a, b int) int { if a &g...
2022-05-31 17:43:08
63
原创 LeetCode 只出现一次的数
Given a non-emptyarray of integers nums, every element appears twice except for one. Use golangf to find that single one.func singleNumber(nums []int) int { single := 0 for _, num := range nums { single ^= num } return single.
2022-05-31 17:41:08
63
原创 二叉树中序遍历
Given the root of a binary tree, use golang to return the inorder traversal of its nodes' values.func inorderTraversal(root *TreeNode) (res []int) { var inorder func(node *TreeNode) inorder = func(node *TreeNode) { if node == nil { return } i
2022-05-31 17:36:09
1081
原创 LeetCode 移除元素
Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.func removeElement(nums []int, val int) int { left := 0 for _, v := range nums { // v 即 nums[right]
2022-05-31 17:32:06
52
原创 合并有序链表
Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.Return the head of the merged linked listfunc mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { head := &ListNode{}
2022-05-31 17:28:35
62
原创 leetcode 7 移除元素(go)
Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.func removeElement(nums []int, val int) int { left := 0 for _, v := range nums { // v 即 nums[right]
2022-03-01 08:25:31
50
原创 leetcode6 移除元素
Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.int removeElement(int* nums, int numsSize, int val){ int k = 0; for(int i=0;i<numsSize;i++) {
2022-03-01 08:23:40
44
原创 leetcode5 合并链表
Merge two ascending chained tables into a new ascending chained table using Cstruct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2){ if(l1==NULL) return l2; if(l2==NULL) return l1; if(l1->val < l2->val
2022-03-01 08:20:29
524
原创 leetcode 4 回文
Determine if a number is a palindromeclass Solution {public: bool isPalindrome(int x) { if (x < 0 || (x % 10 == 0 && x != 0)) { return false; } int revertedNumber = 0; while (x > revertedN.
2022-02-28 19:39:58
50
原创 leetcode 3 阿拉伯数字
Use C to complete the task of converting Roman numerals to Arabic numerals int romanToInt(char * s){ int symbolValues[26]; symbolValues['I' - 'A'] = 1; symbolValues['V' - 'A'] = 5; symbolValues['X' - 'A'] = 10; symbolValues['L' -.
2022-02-28 19:38:59
67
原创 leetcode 2 两数求和 C
Use C to complete the task of summing two numbersint* twoSum(int* nums, int numsSize, int target,int* returnSize) { int i,j; *returnSize=2; int *result=NULL; for(i=0;i<numsSize-1;i++) { for(j=i+1;j<numsSize;j++) .
2022-02-28 19:38:01
106
原创 LeetCode 1 两数求和
Use go language to complete the task of summing two numbersfunc twoSum(nums []int, target int) []int { var re []int for i:=0;i<len(nums)-1;i++{ for j:=i+1;j<len(nums);j++{ if nums[i] + nums[j] ==target{ .
2022-02-28 19:36:56
78
原创 如何在CENTOS以及阿里云ECS上安装go及gin框架
First install the go language compilation environment in CentOS, download the go language archive from the official website and put it in the usr/locao directory, then use the command:tar -C /usr/local/go -zxvf /usr/local/go1.17.6.linux-amd64.tar.gzEx
2022-02-28 19:21:00
396
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人