leetcode Submission Details
代码:
#include<iostream>
#include<vector> using namespace std; struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
}; ListNode* rotateRight(ListNode* head, int k) {
if (head == NULL)
return head;
ListNode * p = head;
int i = ;
while (p->next != NULL)
{
p = p->next;
i++;
}
ListNode * tail = p;
int L = i;
cout << "L = " << L << endl;
k = L - k%L;
cout << "K = " << k << endl;
if (k == L)
return head;
i = ;
p = head;
while (i != k)
{
p = p->next;
i++;
}
cout << "p ="<<p->val << endl;
ListNode *newHead = p->next;
p->next = NULL;
tail->next = head;
return newHead;
} int main()
{
ListNode * head = new ListNode();
ListNode *p = head;
for (int i = ; i <= ; i++)
{
p->next = new ListNode(i);
p = p->next;
}
p = NULL;
for (ListNode * temp = head; temp != NULL; temp = temp->next)
cout << temp->val << endl;
ListNode * newHead = rotateRight(head, );
cout << "-----------------------------------------" << endl;
for (ListNode * temp = newHead; temp != NULL; temp = temp->next)
cout << temp->val << endl;
}
leetcode Submission Details的更多相关文章
- LeetCode——Submission Details
Description: Given a string of numbers and operators, return all possible results from computing all ...
- Submission Details [leetcode] 算法的改进
最先看到这一题,直觉的解法就是len从1到s1.size()-1,递归调用比較s1和s2长度为len的子串是否相等.以及剩余部分是否相等. 将s1分成s1[len + rest],分别比較s2[len ...
- 【leetcode】Submission Details
Given two sentences words1, words2 (each represented as an array of strings), and a list of similar ...
- Submission Details
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode OJ] Max Points on a Line
Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...
- [leetCode][012] Two Sum (1)
[题目]: Given an array of integers, find two numbers such that they add up to a specific target number ...
- [leetCode][016] Add Two Numbers
[题目]: You are given two linked lists representing two non-negative numbers. The digits are stored in ...
- leetcode 15. 3Sum 二维vector
传送门 15. 3Sum My Submissions Question Total Accepted: 108534 Total Submissions: 584814 Difficulty: Me ...
- [sqoop1.99.6] 基于1.99.6版本的一个小例子
1.创建mysql数据库.表.以及测试数据mysql> desc test;+-------+-------------+------+-----+---------+------------- ...
随机推荐
- POI 单元格
OI 单元格合并中的CellRangeAddress 参数: CellRangeAddress(int, int, int, int) 参数:起始行号,终止行号, 起始列号,终止列号 sheet.ad ...
- Java 多个引用类型变量引用同一个对象
引用类型变量在声明后必须引用对象才能使用. 一个引用变量只能唯一指向一个对象,但同一个对象可被多个引用类型变量引用. 如:MyDate today; //将变量跟配给一个保存引用的空间(栈) toda ...
- show-overflow-tooltip 宽度设置
设置样式:不能放在scoped中 <style lang="scss"> .el-tooltip__popper{max-width:80%}</style> ...
- sqldeveloper和plsqldebeloper
sqldeveloper : 支持不用tns连,支持jdbc直接连的. plsqldebeloper : 必须使用tns连, 如果oracle安装在本机,本机已经有tns文件,和oci.dll,只需在 ...
- Composer安装使用
Composer 是 PHP5.3以上 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 1.下载 2.安装成功 3.配置地址 4.安装代码库 镜像 配置json
- python下载指定页面的所有图片
实现步骤: 1.下载页面源码 2.对页面进行解析,获取页面中所有的图片路径 3.下载图片到指定路径 代码实例: # coding: utf-8 import urllib2 # 该模块用于打开页面地址 ...
- 字符串,字符数组(C/C++)
这个地方困惑我好久了,废话不多说 char c1[]="12345"; char *c2="12345"; string c3="12345" ...
- vsftpd设置被动模式
完整配置 listen=yes listen_port= max_clients= max_per_ip= local_max_rate= anonymous_enable=no local_enab ...
- Python多线程-线程锁
多线程修改一份数据时需要用到线程锁,以防止数据修改出错 #-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import threa ...
- java成神之——数值操作BigDecimal,BigInteger,Random,SecureRandom
数值操作 数值新特性 包装类 浮点 BigDecimal BigInteger 数值本地化 随机数 假随机数 真随机数 播种 结语 数值操作 数值新特性 123_456 等价于 123456,增加可读 ...