海上月是天上月,眼前人是心上人。
01 2022 档案
摘要:while(x) { number++; x=x&(x-1); }
阅读全文
摘要:一、int 类型转换为 string 类型 string s=to_string(asum+bsum);//int 转化为 string string/char 转换为 int 类型 1、首先将 字符串string 转为 C语言中的 const char* 类型(使用 _c.str()函数) 2、将
阅读全文
摘要:class Solution { public: ListNode* reverseList(ListNode* head) { ListNode *p; for(p=NULL; head; swap(head,p)) swap(p,head->next); return p; } };
阅读全文
摘要:class Solution { public: bool hasCycle(ListNode *head) { ListNode* fast=head,* slow=head; while(fast&&fast->next) { fast=fast->next->next; slow=slow->
阅读全文
摘要:题目:给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。 不需要额外空间的方法,就往位运算上想,这里使用异或。 0与任何数字异或都是其本身,而相同的数字异或结果为0。 int singleNumber(vector<int>& nums) { in
阅读全文
摘要:#include <stdio.h> #define BUFSIZE 50 int main() { FILE* f; char buf[BUFSIZE] = "this is fputs function!\n hello fputs!"; f=fopen("D:\\1.txt","w"); if
阅读全文
摘要:#include <stdio.h> int main() { FILE* fp; char buf[20]; //打开文件 fp = fopen("D:\\1.txt", "r"); //判断是否成功 if (fp == NULL) { printf("打开文件失败"); } //获取文件 whi
阅读全文
摘要:int removeElement(vector<int>& nums, int val) { int k=0; for(int i=0;i<nums.size();i++) { if(nums[i]!=val) { nums[k++]=nums[i]; } } return k;
阅读全文
摘要:int j=0; for(int i=1;i<nums.size();i++) { if(nums[j]!=nums[i]) { nums[++j]=nums[i]; } }
阅读全文
摘要:ofstream是从内存到硬盘,ifstream是从硬盘到内存。 在实际应用中,根据需要的不同,选择不同的类来定义;如果想以输入方式打开,就用ifstream;如果想以输出方式打开,就用ofstream来定义;如果想以输入/输出方式来打开,就用fstream来定义。 如果想读取一个文件的内容,那么首
阅读全文