Re: [閒聊] 每日LeetCode

看板Marginalman作者 (みけねこ的鼻屎)時間2年前 (2023/01/03 16:03), 2年前編輯推噓6(604)
留言10則, 7人參與, 2年前最新討論串175/719 (看更多)
944. Delete Columns to Make Sorted 給你一個字串陣列表示的矩陣,若該矩陣的行不是由字典序小到大排序則移除之,判斷 有幾個行需要移除。 Example: Input: strs = ["cba","daf","ghi"] Output: 1 Explanation: The grid looks as follows: cba daf ghi Columns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column. 思路: 1.對每一個行遍歷並檢查是否有排序,若沒排序就讓removed加一。 2.返回removed。 Java Code: --------------------------------- class Solution { public int minDeletionSize(String[] strs) { int removed = 0; for (int i = 0; i < strs[0].length(); i++) { for (int j = 1; j < strs.length; j++) { if (strs[j].charAt(i) < strs[j - 1].charAt(i)) { removed++; break; } } } return removed; } } --------------------------------- -- https://i.imgur.com/3e5CZfj.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.100.75.86 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1672733008.A.1AF.html

01/03 16:03, 2年前 , 1F
大師
01/03 16:03, 1F
※ 編輯: Rushia (122.100.75.86 臺灣), 01/03/2023 16:04:06

01/03 16:08, 2年前 , 2F
這什麼奇怪的要求
01/03 16:08, 2F

01/03 16:10, 2年前 , 3F
大師
01/03 16:10, 3F

01/03 16:10, 2年前 , 4F
處理string用 charat跟 [ ] 有差嗎
01/03 16:10, 4F

01/03 16:11, 2年前 , 5F
java一律用chatAt
01/03 16:11, 5F

01/03 16:11, 2年前 , 6F
聊天室在哪裡
01/03 16:11, 6F

01/03 16:12, 2年前 , 7F
喔喔 這是java
01/03 16:12, 7F

01/03 16:19, 2年前 , 8F
JAVA的字串是class
01/03 16:19, 8F

01/03 16:23, 2年前 , 9F
c++的也是class 不過c++有運算子重載
01/03 16:23, 9F

01/03 17:01, 2年前 , 10F
你真的好厲害:0
01/03 17:01, 10F
文章代碼(AID): #1Zi-5G6l (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1Zi-5G6l (Marginalman)