剑指offer
表示数值的字符串
相似的企业真题
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 64M,其他语言128M
热度指数:310131
本题知识点:
字符串
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。
示例1
输入
复制
"123.45e+6"
"123.45e+6"
返回值
复制
true
true
示例2
输入
复制
"1.2.3"
"1.2.3"
返回值
复制
false
false
上一题
登录
/
注册
我的提交
编辑器加载中...
public class Solution { public boolean isNumeric(char[] str) { } }
class Solution { public: bool isNumeric(char* string) { } };
# -*- coding:utf-8 -*- class Solution: # s字符串 def isNumeric(self, s): # write code here
class Solution { public bool isNumeric(char[] str) { // write code here } }
//s字符串 function isNumeric(s) { // write code here } module.exports = { isNumeric : isNumeric };
//s字符串 function isNumeric(s) { // write code here }
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return bool布尔型 */ func isNumeric( s string ) bool { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param s string字符串 # @return bool布尔型 # class Solution def isNumeric(s) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return bool布尔型 */ def isNumeric(s: String): Boolean = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return bool布尔型 */ fun isNumeric(s: String): Boolean { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return bool布尔型 */ public boolean isNumeric (String s) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return bool布尔型 */ export function isNumeric(s: string): boolean { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return bool布尔型 */ func isNumeric ( _ s: String) -> Bool { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return bool布尔型 */ pub fn isNumeric(&self, s: String) -> bool { // write code here } }
"123.45e+6"
true
"1.2.3"
false