博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
三步翻转法
阅读量:4363 次
发布时间:2019-06-07

本文共 1994 字,大约阅读时间需要 6 分钟。

在原字符串中把字符串尾部的m个字符移动到字符串的头部。

class Solution {    public void reverse(char[] ch, int l ,int r) {        for ( ; l

  1. Reverse Nodes in k-Group
    Hard

1244

257

Favorite

Share

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.

k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.

Example:

Given this linked list: 1->2->3->4->5

For k = 2, you should return: 2->1->4->3->5

For k = 3, you should return: 3->2->1->4->5

Note:

Only constant extra memory is allowed.

You may not alter the values in the list's nodes, only nodes itself may be changed.

1184092-20190714191852514-773867530.png

/** * Definition for singly-linked list. * public class ListNode { *     int val; *     ListNode next; *     ListNode(int x) { val = x; } * } */class Solution {    public ListNode reverseKGroup(ListNode head, int k) {        ListNode dummy = new ListNode(0);        dummy.next = head;        ListNode pre = dummy;        ListNode end = dummy;        while(end.next != null){            for(int i=0; i

【151. Reverse Words in a String】

Given an input string, reverse the string word by word.

Example 1:

Input: "the sky is blue"

Output: "blue is sky the"
Example 2:

Input: " hello world! "

Output: "world! hello"
Explanation: Your reversed string should not contain leading or trailing spaces.
Example 3:

Input: "a good example"

Output: "example good a"
Explanation: You need to reduce multiple spaces between two words to a single space in the reversed string.

Note:

A word is defined as a sequence of non-space characters.

Input string may contain leading or trailing spaces. However, your reversed string should not contain leading or trailing spaces.
You need to reduce multiple spaces between two words to a single space in the reversed string.
【代码】

class Solution {    public void reverse(char[] ch,int l,int r){        while(l

转载于:https://www.cnblogs.com/Roni-i/p/11185170.html

你可能感兴趣的文章
node 爬虫(-)
查看>>
Unity部署的EXE文件双击后没有任何反应(Crash)--Q盾这个坑!
查看>>
线程,进程,IO多路复用,协程的代码
查看>>
集线器(HUB)、交换机、路由器的区别和联系 及OSI七层模型 及TCP/IP通信协议...
查看>>
7.29多态
查看>>
spring入门之环境搭建
查看>>
ORM中一个很重要的方法BuildConditionSetSql
查看>>
Youth -Samuel Ullman
查看>>
day06_方法_20150806
查看>>
wamp安装后打开默认网页显示dir,图标红点
查看>>
javascript参考手册CHM中文版,以及PHP,MYSQL,DHTML参考手册下载
查看>>
勒索病毒数据库恢复 勒索病毒解密恢复 中勒索病毒解密恢复数据
查看>>
[AMPPZ2014]Petrol
查看>>
移动端开发注意事项
查看>>
剖析WPF数据绑定机制
查看>>
学习进度条
查看>>
sublime text3 配置tab为4个空格
查看>>
window7 更改电脑黑屏时间
查看>>
Windows使用小技巧——如何在任务栏上新建自定义工具栏,快速打开常用文件
查看>>
php输出错误信息
查看>>