Given a string S, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their positions.   Example 1: Input: "ab-cd" Output: "dc-ba" Example 2: Input: "a-…
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them. If there are less than 2k but greater than or eq…
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1: Input: "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc"…
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Sol…
problem 917. Reverse Only Letters solution: class Solution { public: string reverseOnlyLetters(string S) { , j=S.size()-; i<j; )//err... { if(!isalpha(S[i])) i++; else if(!isalpha(S[j])) j--; else { char tmp = S[i]; S[i] = S[j]; S[j] = tmp; i++; j--;…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 单指针 双指针 日期 题目地址: https://leetcode.com/contest/weekly-contest-105/problems/reverse-only-letters/ 题目描述 Given a string S, return the "reversed" string where all characters…
Given a string S, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their positions. Example 1: Input: "ab-cd" Output: "dc-ba" Example 2: Input: "a-bC…
题目要求 Given a string S, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their positions. 题目分析及思路 给定一个字符串,返回“reversed”后的字符串,要求非字母的字符保留原来的位置,字母字符逆序排列.可以先获得原字符串中的全部字母字符列表,然后遍历原字…
https://leetcode.com/problems/reverse-only-letters/ Given a string S, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their positions.   Example 1: Input: "ab-cd"…
Given a string s, reverse the string according to the following rules: All the characters that are not English letters remain in the same position. All the English letters (lowercase or uppercase) should be reversed. class Solution { public: string r…