首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
01串修改
[编程题]01串修改
热度指数:1203
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给定一个只包含'0'和'1'两种字符的字符串,每次操作可以选择相邻的两个字符,将它们同时变成'0'或者同时变成'1'。
请问最少多少次操作后,所有的字符都相同?
字符串长度不超过1000。
示例1
输入
"1001101"
输出
2
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(3)
邀请回答
收藏(34)
分享
纠错
提交结果有问题?
12个回答
1篇题解
开通博客
纳姆德隆
发表于 2023-05-27 16:04:31
class Solution { public: int minOperations(string str) { &
展开全文
问题信息
上传者:
小小
难度:
12条回答
34收藏
4373浏览
热门推荐
通过挑战的用户
Shockshock
2023-03-13 13:59:51
ACID2020
2023-03-11 16:23:51
小何...
2023-03-10 19:54:09
iloveno...
2023-03-03 10:14:44
LZY2024
2023-02-23 20:25:24
相关试题
在 非严格模式下 javaScri...
Javascript
评论
(1)
关于语句 A a = new A(...
Java
评论
(1)
在大规模分布式训练大型语言模型时,...
大模型开发
评论
(1)
当一个系统应该独立于它的产品创建,...
设计模式
评论
(2)
哪些情况建立索引会降低查询效率( )
数据库
评论
(2)
01串修改
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ public int minOperations (String str) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ int minOperations(string str) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param str string字符串 # @return int整型 # class Solution: def minOperations(self , str ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ public int minOperations (string str) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ function minOperations( str ) { // write code here } module.exports = { minOperations : minOperations };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param str string字符串 # @return int整型 # class Solution: def minOperations(self , str: str) -> int: # write code here
package main //import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ func minOperations( str string ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ int minOperations(char* str ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param str string字符串 # @return int整型 # class Solution def minOperations(str) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ def minOperations(str: String): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ fun minOperations(str: String): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ public int minOperations (String str) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ export function minOperations(str: string): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ func minOperations ( _ str: String) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ pub fn minOperations(&self, str: String) -> i32 { // write code here } }
"1001101"
2