题目

    Write a function to find the longest common prefix string amongst an array of strings.

代码

public class Solution {public String longestCommonPrefix(String[] strs) {if(strs.length==0) return "";if(strs.length==1) return strs[0];String commonPrefix="";boolean end=true;char strChar[]=strs[0].toCharArray();ok:for (int j = 0;j<strChar.length;j++){for(int i=1;i<strs.length;i++){char tempChar[]=strs[i].toCharArray();int tempChar_length=tempChar.length;if(j<tempChar_length){if(tempChar[j]==strChar[j]){}else{break ok; }}else{break ok;}} commonPrefix+=strChar[j];}return commonPrefix;}
}
代码下载:https://github.com/jimenbian/GarvinLeetCode

/********************************

* 本文来自博客  “李博Garvin“

* 转载请标明出处:http://blog.csdn.net/buptgshengod

******************************************/

【LeetCode从零单排】No14.LongestCommonPrefix相关推荐

  1. 【LeetCode从零单排】No198.House Robber No91.Decode Ways139 word break(动态规划典型应用)

    1.题目 一道典型的Dynamic Programming的题目. You are a professional robber planning to rob houses along a stree ...

  2. 【LeetCode从零单排】No70.ClimbingStairs

    题目 爬楼梯问题,这是一道很有趣的问题.首先看题目: You are climbing a stair case. It takes n steps to reach to the top. Each ...

  3. 【LeetCode从零单排】No26.Remove Duplicates from Sorted Array

    题目      题目要求:去除sort int数组中的重复项. Given a sorted array, remove the duplicates in place such that each ...

  4. 【LeetCode从零单排】No.7 Reverse Integer

    前话       今天开始励志刷一下leetcode上面的题目(还好这个网站没被TG和谐).从easy的开始,数一下差不多有40道,争取两个月搞定. 题目        没想到做的第一道题目,虽然看似 ...

  5. 【LeetCode从零单排】No.135Candy(双向动态规划)

    1.题目 There are N children standing in a line. Each child is assigned a rating value. You are giving ...

  6. 【LeetCode从零单排】No22.Generate Parentheses

    题目 Given n pairs of parentheses, write a function to generate all combinations of well-formed parent ...

  7. 【LeetCode从零单排】No221.Maximal Square

    题目 Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...

  8. 【LeetCode从零单排】No133. clon graph (BFS广度优先搜索)

    背景 (以下背景资料转载自:http://www.cnblogs.com/springfor/p/3874591.html?utm_source=tuicool) DFS(Dpeth-first Se ...

  9. 【LeetCode从零单排】No121 Best Time to Buy and Sell Stock

    题目 Say you have an array for which the ith element is the price of a given stock on day i. If you we ...

最新文章

  1. 隐马尔科夫模型HMM(一)HMM模型
  2. 代码 设计 生活 (2)--- 菜鸟
  3. 用matlab编辑器打开.m文件
  4. 基于Node的Koa2项目从创建到打包到云服务器指南
  5. js异步加载 defer和async 比较
  6. 论程序员如何规划职业路线?网友:从码农到工程师?
  7. vue中$watch源码阅读笔记
  8. 一个 union all 的all
  9. VS2013的一些常用快捷键
  10. 天勤2022数据结构(二)栈和队列
  11. 机器学习(周志华) 第十六章强化学习
  12. 生物信息学 之 序列比对
  13. 北大公开课计算机,清华、北大、浙大的计算机课程资源集都在这里了
  14. 《清单革命》:让大脑处理更重要的事情
  15. Kermit,Xmodem,1K-Xmodem,Ymodem,Zmodem传输协议小结
  16. 全差分运算放大器浅析
  17. AWVS扫描web站点
  18. kuka机器人offset指令_KUKA机器人MADA详解.doc
  19. 2-appium之adb介绍
  20. CEPH分布式存储介绍与原理架构概述

热门文章

  1. PAT甲级1139 First Contact (30 分):[C++题解] 图论、暴力枚举两个点、hash映射
  2. mysql主从同步默认延迟_减少mysql主从数据同步延迟问题的详解
  3. 易语言开发c s,Grid++Report报表工具C/S实战项目演练
  4. python如何下载tushare_安装tushare
  5. python逻辑运算符不懂_Python运算符之逻辑运算符
  6. c++ opencv编程实现暗通道图像去雾算法_OpenCV图像处理专栏十五 |一种基于亮度均衡的图像阈值分割技术...
  7. oracle中dlink使用,Oracle,MetaLink,中文使用指南
  8. a eraser eraser还是an_eraser前面用a还是an
  9. win10怎么用Linux命令,教你Windows10系统使用Linux命令的技巧
  10. orm mysql_ORM介绍